You are not logged in.

#1 2016-11-07 09:49:35

mikaelbrun
Member
From: Tistedal/ Norway
Registered: 2016-01-01
Posts: 43

[SOLVED]Need help understanding friendship with classes (C++)

As I'm learning C++, I use some tutorials as reference.
One tutorial I have been reading has a line I don't understand, and I hope someone can explaine it to me.
The line is:

Square (int a) : side(a) {}

and what I don't understand is what ":" is doing. And "Square (int a)" I don't fully understand. I guess that "Square" is the class, but "(int a)", is that a parameter?
"side(a) is the function with "a" as parameter, but why do we have the curly bracets after the function?
I tried to find some info on this but couldn't find this part.

And I post this here because I'm already a member of this forum. :-)

The complete code is:

// friend class
#include <iostream>
using namespace std;

class Square;

class Rectangle {
    int width, height;
  public:
    int area ()
      {return (width * height);}
    void convert (Square a);
};

class Square {
  friend class Rectangle;
  private:
    int side;
  public:
    Square (int a) : side(a) {}
};

void Rectangle::convert (Square a) {
  width = a.side;
  height = a.side;
}
  
int main () {
  Rectangle rect;
  Square sqr (4);
  rect.convert(sqr);
  cout << rect.area();
  return 0;
}

Last edited by mikaelbrun (2016-11-22 08:09:09)

Offline

#2 2016-11-07 13:40:31

ColdPhoenix2
Member
Registered: 2016-10-15
Posts: 8

Re: [SOLVED]Need help understanding friendship with classes (C++)

Square(int a)

is a constructor of class Square. Constructor is a special member function that is called when object is created. You can find more about them on the internet.

: side(a)

is an initialization list. It is equivalent to:

Square(int a)
{
    side = a;
}

but it's faster when you use initialization list. It can be also used to call functions or constructor of a parent class(for example, in wxWidgets when you want to subclass a widget)
PS Your problem has nothing to do with friendship.

Last edited by ColdPhoenix2 (2016-11-07 13:48:11)

Offline

#3 2016-11-07 14:52:02

mpan
Member
Registered: 2012-08-01
Posts: 1,188
Website

Re: [SOLVED]Need help understanding friendship with classes (C++)

mikaelbrun:
ColdPhoenix2 has already explained that this has nothing to do with friendship, but your use of friend requires a comment — you’re using it wrong, breaking the encapsulation. Or actually a bit of worse than that: you’re breaking it, while pretending you’re not doing so.

The friendship mechanism of C++ is meant to be used for definitions that are part of class’s interface¹, but for some reason can’t be defined inside the class itself. A common examples are overloads of ::std::swap, overloads of operators and similar things. Nothing you’ll encounter while learning the most basic parts of C++. It’s pretty hard to consider Rectangle to be part of what Square provides.

If you want another, separate, unrelated class to have access to length of a Rectangle’s side, just design Rectangle so it provides that information. No need to pretend it is not doing so.

The second thing is that the constructor of Rectangle is wrong. Well… actually it’s not written at all, but this means the default one is provided, which does nothing in this case. The effect is that upon creation the Rectangle instance is left uninitialized.

Hence:

// Copyright © 2016 mpan; <https://mpan.pl/>; CC0 1.0
// Response to: <https://bbs.archlinux.org/viewtopic.php?id=219258>
#include <iostream>
#include <cstdlib>

class Square final
{
    private:
        unsigned int const side;
        
    public:
        Square(unsigned int side)
            : side(side) {} // Ignoring testing for 0
        
        unsigned int getSideLength() const
        {
            return side;
        }
};

class Rectangle final
{
    private:
        unsigned int const height;
        unsigned int const width;
        
    public:
        Rectangle(unsigned int height, unsigned int width)
            : height(height), width(width) {} // Ignoring testing for 0
        
        Rectangle(Square const& square)
            : Rectangle(square.getSideLength(), square.getSideLength()) {}
        
        unsigned int getArea() const
        {
            return height * width; // Blindly assuming no overflow
        }
};

int main()
{
    Square square(4);
    Rectangle rectangle(square);
    
    ::std::cout << "Rectangle area: " << rectangle.getArea() << '\n';
    
    return EXIT_SUCCESS;
}

In the above code error handling is ommited for clarity; comments are provided where problems may arise because of that.

____
¹ “Interface” in general OOP meaning — not to be confused with a particular OOP construct.


Sometimes I seem a bit harsh — don’t get offended too easily!

Offline

#4 2016-11-07 21:16:31

mikaelbrun
Member
From: Tistedal/ Norway
Registered: 2016-01-01
Posts: 43

Re: [SOLVED]Need help understanding friendship with classes (C++)

mpan wrote:

...your use of friend requires a comment — you’re using it wrong, breaking the encapsulation. Or actually a bit of worse than that: you’re breaking it, while pretending you’re not doing so.

This is actually not my program. It is an example picked up at: http://www.cplusplus.com/doc/tutorial/inheritance/

But I am working on a small program I use for learning and understanding.
Part of the program is using colors for max and min, and converted from hex to RGB.

My thougts is something like
(The syntax is just for illustration of my idea.)

class HEXCOLOR
{
    convertToRGB(hex_value) ;
    // This function needs to be executed for both max  and min
    // max.convertToRGB(max_hex_value)
    // min.convertToRGB(min_hex_value)
};

class RGBCOLOR
{
    someFunction(HEXCOLOR obj) ;
    // This function will be executed for each RGB value for both 
    // max.convertToRGB() and min.convertToRGB()
    // r.someFunction(HEXCOLOR max) 
    // r.someFunction(HEXCOLOR min)
    // g.someFunction(HEXCOLOR max)
    // g.someFunction(HEXCOLOR min) 
    // ......
};

I thought maybe use of friendship will make this happen, or may I overload within a class? (I don't have full controll over my understanding for overloading yet)
Is this a good thought, or should I use a different aproach to the problem?
(I have another post on this program, and this is the continued work from that: https://bbs.archlinux.org/viewtopic.php?id=219008)

Offline

#5 2016-11-10 23:47:54

mpan
Member
Registered: 2012-08-01
Posts: 1,188
Website

Re: [SOLVED]Need help understanding friendship with classes (C++)

I’m not entirely sure, what are you trying to achieve with this. First of all, what HexColor¹ and RgbColor represent? What are the methods you want to implement and what should they do?
____
¹ Yes, don’t use all-upper case names for anything except what they’re commonly used for: macros. Otherwise you risk conflict between these two and painful, hard to understand errors.


Sometimes I seem a bit harsh — don’t get offended too easily!

Offline

#6 2016-11-17 10:25:31

mikaelbrun
Member
From: Tistedal/ Norway
Registered: 2016-01-01
Posts: 43

Re: [SOLVED]Need help understanding friendship with classes (C++)

mpan wrote:

I’m not entirely sure, what are you trying to achieve with this. First of all, what HexColor¹ and RgbColor represent? What are the methods you want to implement and what should they do?

This will explain what I want to achieve.

I have read more about classes, friendship and so on, and I have started to look into the use of constructors.
I think that if I manage to use this the right way, my program will work pretty much as I want to.

Offline

#7 2016-11-19 00:03:52

mpan
Member
Registered: 2012-08-01
Posts: 1,188
Website

Re: [SOLVED]Need help understanding friendship with classes (C++)

If you want to see the answer only, skip the following two paragraphs.
I’m not that stupid to not see the linked topic and read your comments in it big_smile. But that doesn’t explain me much. There is no need for any HexColor or RgbColor, and there is no explaination of what would they represent. From the name of classes I could guess that they are describing a color, but what are “Rgb” and “Hex”? And, again, I’m not so stupid to not be able to guess some possibilities. The problem is  that my guess leads to a blind spot: because if you’re referring to a hexadecimal RGB representation of a color and some other, unspecified RGB representation of a color… they are both just a color, exactly the same thing, described by the same class. Makes no sense. Hence the question.

You have also written:

mikaelbrun wrote:

My thoughts is to at least put the color part as a class with functions. The conversion of the hex-color should output the the RGB values. The new color should maybe be a sub class of the color, and should be converted back to hex format. The temperature could be a class, and the calculation of the temperature factor could be a sub class.

But your goal was: the color is changing with smooth transition between a cold color and a hot color. Anything about converting colors between any particular representations? See the problem?

Based on my understanding of your problem as described now¹, you need a single class that will represent a color and a method that will calculate interpolation between it and another color. Nothing more:

// Copyright © 2016 mpan; <https://mpan.pl/>; CC0 1.0
/**
 * A color.
 */
class Rgb24Color final
{
    public:
        /**
         * Performs linear interpolation between this color and @p rhs,
         * providing the value at @p position.
         * 
         * @param [in] rhs
         *      The second color for the interpolation with this one.
         * @param [in] position
         *      The position for the interpolation, in range [0; 1].
         * 
         * @return
         *      A value at @p position between this color and @p rhs.
         */
        Rgb24Color interpolateTo(Rgb24Color const rhs, double position) const;
};

And the full implementation using a linear RGB interpolation:

// Copyright © 2016 mpan; <https://mpan.pl/>; CC0 1.0
#include <iostream>
#include <limits>
#include <sstream>
#include <stdexcept>
#include <cassert>
#include <cmath>
#include <cstdlib>

#if !__GNUC__
    #define __attribute__(attrs) 
#endif // else: skip; leave __attribute__ in GCC

/**
 * A color stored as RGB channels, 8 bits per channel.
 */
class Rgb24Color final
{
    public:
        /**
         * Creates an instance of `Color` by specifying red, green and blue
         * channels separately as values in range [0; 255] (total darkness
         * to full brightness).
         * 
         * @param [in] red
         *      The value of the red channel.
         * @param [in] green
         *      The value of the green channel.
         * @param [in] blue
         *      The value of the blue channel.
         */
        Rgb24Color(unsigned char red, unsigned char green, unsigned char blue);
        
        /**
         * Performs linear interpolation between this color and @p rhs,
         * providing the value at @p position.
         * 
         * @param [in] rhs
         *      The second color for the interpolation with this one.
         * @param [in] position
         *      The position for the interpolation, in range [0; 1].
         * 
         * @return
         *      A value at @p position between this color and @p rhs.
         */
        Rgb24Color interpolateTo(Rgb24Color const rhs, double position) const;
        
        /**
         * Delivers the value of the red channel.
         * 
         * @return
         *      The value of the red channel, in range [0; 255] (total darkness
         *      to full brightness).
         */
        unsigned char getRed() const;
        
        /**
         * Delivers the value of the green channel.
         * 
         * @return
         *      The value of the green channel, in range [0; 255] (total
         *      darkness to full brightness).
         */
        unsigned char getGreen() const;
        
        /**
         * Delivers the value of the blue channel.
         * 
         * @return
         *      The value of the blue channel, in range [0; 255] (total darkness
         *      to full brightness).
         */
        unsigned char getBlue() const;
        
    private:
        /**
         * The minimum value of a channel.
         */
        static constexpr unsigned char const channelMin = 0;
        
        /**
         * The maximum value of a channel.
         */
        static constexpr unsigned char const channelMax = 255;
        
        /**
         * Determines if @p value is a valid channel value.
         * 
         * @retval `true`
         *      @p value is a valid channel value.
         * @retval `false`
         *      @p value is not a valid channel value.
         */
        static constexpr bool isValidChannel(unsigned char value);
        
        /**
         * Calculates linear interpolation at @p position
         * between @p lhs and @p rhs.
         * 
         * @param [in] lhs
         *      The left-hand side of the interpolation.
         * @param [in] rhs
         *      The right-hand side of the interpolation.
         * @param [in] position
         *      The position for the interpolation, in range [0; 1].
         * 
         * @return
         *      `lhs · position + rhs · (1 - position)`
         */
        static unsigned char interpolate(
          unsigned char lhs, unsigned char rhs, double position);
        
        /**
         * Value of the red channel, in range [0; 255] (total darkness to full
         * brightness.
         */
        unsigned char const red;
        
        /**
         * Value of the green channel, in range [0; 255] (total darkness to full
         * brightness.
         */
        unsigned char const green;
        
        /**
         * Value of the blue channel, in range [0; 255] (total darkness to full
         * brightness.
         */
        unsigned char const blue;
};

Rgb24Color::Rgb24Color(unsigned char const red, unsigned char const green,
  unsigned char const blue)
    : red(red), green(green), blue(blue)
{
    if (!isValidChannel(red))
    {
        throw ::std::invalid_argument("`red` is not a valid channel value.");
    }
    else if (!isValidChannel(green))
    {
        throw ::std::invalid_argument("`green` is not a valid channel value.");
    }
    else if (!isValidChannel(blue))
    {
        throw ::std::invalid_argument("`blue` is not a valid channel value.");
    } // else: continue; everything is ok
}

Rgb24Color Rgb24Color::interpolateTo(
  Rgb24Color const rhs, double const position) const
{
    if (position >= 0 && position <= 1)
    {
        return Rgb24Color(
          interpolate(getRed(), rhs.getRed(), position),
          interpolate(getGreen(), rhs.getGreen(), position),
          interpolate(getBlue(), rhs.getBlue(), position));
    }
    else
    {
        throw ::std::domain_error("`position` is not in [0; 1].");
    }
}

unsigned char Rgb24Color::getRed() const
{
    return red;
}

unsigned char Rgb24Color::getGreen() const
{
    return green;
}

unsigned char Rgb24Color::getBlue() const
{
    return blue;
}

constexpr bool Rgb24Color::isValidChannel(unsigned char const value)
{
    #if __GNUC__
        #pragma GCC diagnostic push
        #pragma GCC diagnostic ignored "-Wtype-limits"
    #endif
    return value <= channelMax;
    #if __GNUC__
        #pragma GCC diagnostic pop
    #endif
}

unsigned char Rgb24Color::interpolate(
  unsigned char const lhs, unsigned char const rhs, double const position)
{
    double result;
    
    assert(isValidChannel(lhs));
    assert(isValidChannel(rhs));
    assert(position >= 0 && position <= 1); // Handles NaN
    
    result = ::std::round(lhs * (1 - position) + rhs * position);
    return static_cast<unsigned char>(::std::fmax(double(channelMin),
      ::std::fmin(double(channelMax), result)));
}

int main(int argc __attribute__((unused)), char** argv)
{
    if (nullptr != argv[1])
    {
        ::std::istringstream argIn(argv[1]);
        Rgb24Color from(255, 0, 0);
        Rgb24Color to(0, 255, 0);
        double position;
        int dummy;
        bool readPosition;
        
        argIn >> position;
        readPosition = bool(argIn);
        argIn >> dummy;
        if (readPosition && argIn.eof() && position >= 0 && position <= 1)
        {
            Rgb24Color const interpolated = from.interpolateTo(to, position);
            ::std::cout << "Interpolated: (" << int(interpolated.getRed())
                        << ", " << int(interpolated.getGreen())
                        << ", " << int(interpolated.getBlue()) << ").\n";
            return EXIT_SUCCESS;
        }
        else
        {
            ::std::cerr << "Failed to read the argument as a position\n";
            return EXIT_FAILURE;
        }
    }
    else
    {
        ::std::cerr << "Syntax: " << argv[0] << " POSITION\n"
                       "Where `POSITION` is in range [0; 1].\n";
        return EXIT_FAILURE;
    }
}

What you should pay attention to in this code is actually not how code a color — in fact you could just go with ::std::uint_least32_t from header cstdint and a single function that would do interpolation. For such a simple program it’s not worth creating a separate class — as you see it’s longer than your whole code. Your main problem is of different nature: how to do interpolation. In this example I have deliberately choosen full red () and full green (). They will produce something that, I believe, is not you want:
███











███ (above as an image)
In the middle we see… a dirty brownish something, darker than either of the ends; not — as you would expect — a nice, clear yellow. This is caused by using wrong space. RGB doesn’t take into account components that are important to the human eye. If you want better results, consider working in HSL, HSV or YCrCb spaces. Just be aware than HSL and HSV have H channel in polar coördinates, which — again — gives at least two methods of interpolating. May be not worh a work for a simple program like the one you have described — in this case it may be simpler to just let the user define 1–2 additional points inside the gradient. But if you want to make it properly, the mentioned spaces are what you want.
____
¹ And don’t blame me for bad understanding.

Last edited by mpan (2016-11-19 00:11:47)


Sometimes I seem a bit harsh — don’t get offended too easily!

Offline

#8 2016-11-20 11:07:25

mikaelbrun
Member
From: Tistedal/ Norway
Registered: 2016-01-01
Posts: 43

Re: [SOLVED]Need help understanding friendship with classes (C++)

mpan wrote:

But your goal was: the color is changing with smooth transition between a cold color and a hot color. Anything about converting colors between any particular representations? See the problem?

Yes, my goal is a program that gives a smooth transition based on a parameter (in this case, temperature), but the main goal is understanding C++ programming and learn how to make the right thing happen. I am not skilled at this at all, and I really appriciate your answer (detailed and well explained).

I'm currently focusing on learning to use classes. Functions I feel I have a good understanding of (even thoug I know I have much more to learn).

mpan wrote:

What you should pay attention to in this code is actually not how code a color — in fact you could just go with ::std::uint_least32_t from header cstdint and a single function that would do interpolation.

There's no doubt that I could find an easier way to figure this out, and use libraries that has the functionality I look for, but then I would use a shortcut, and not experience all the beauty the hard way could offer. If I was more skilled than I am, I probably would have used existing libraries, and added more code to ensure any faults will be handled correctly, like I see in your code.

mpan wrote:

For such a simple program it’s not worth creating a separate class — as you see it’s longer than your whole code.

I have been told smile , but again, I need experience with classes and general C++ programming, so I make it big, but try to keep it small.
My focus now is to be smart about how to use the functions and classes, so the code gets as small as possible.
I currently has made a constructor that separate the RGB values from the hex, but I can't figure out if I can pick up those variables in each of the classes. The only way I can see that's possible (without using spesific function for it) is by using struct.
I am improving my script, but will come back to it later. I hope you will continue following this post, mpan, so I can get your help further on smile

mpan wrote:

If you want better results, consider working in HSL, HSV or YCrCb spaces.

This is words I have seen somewhere, but never learned what is. This is a good tip, I will consider when I get the hang of my classes smile .

EDIT: My code so far

// Dynamic coloring based on a propertie like:
// * Tempearature
// * Wifi-conection
// * Memory use
// * ...


// ========== Comments ==========
/* 
   I have not tried to compile and run the program since it's not 
   finished yet. 
   
   Looking on programs from more skilled people, I can see that my 
   naming could be better, but at least it's clear what the variables 
   is (I hope) 

   todo list: 
   * figure out how to pick up variables from the right class
     (start and end)
   * figure out how newRGB(channel) can tell every function 
     that this is the variables your are looking for
     (red need red variables either in start or end class
      green need green variables in start or end class
      blue need blue variables in start or end class)
   * add constructors to class RGB (??)
   * currentValue must be extracted from the right instance 
   * max and min values should be automaticly extracted
    (external programs)
   * add user arguments when running the program
    (dyncolor <instance> <param> <start_color> <end_color>)
    (Example: dyncolor GPU temp #000000 #FFFFFF)
   ...
*/


#include <iostream>
using namespace std;

// Global variables
int startColor = 0x00FF00; // Default value green 
int endColor = 0xFF0000; // Default value red
int startParam = 30; // Just setting a number
int endParam = 70; // Again setting a number 

// Declaring classless functions
int factor();
unsigned long dynamicColor();


// ========== CLASSES ==========
class Color
{
private:
  // Variables shared with derived classes and friends
  int red, green, blue;
  int value;
	
public: 
  Color(int, int); // Constructor for start and end (cold and hot)
  ~Color(); // Destructor 
};


Color::Color(int color, int param) // Constructor definition
{
  // How can I refer to these varibles as hot.varible and cold.variable?
  red = ((color >> 16) & 0xFF); // extract red 
  green = ((color >> 8) & 0xFF); // extract green
  blue = (color & 0xFF); // extract blue
  value = param; // param could be temperature, wifi-conection ...
}

Color::~Color(void) { }// Destructor definition



// Derived class
class RGB : public Color
// Should this be private since I want to pick up the private variables
// red, green, blue and param?
// I have not set any constructors, but I believe I should 
{
private:

public:
  // Creating classes 
  Color start(startColor, startParam); // Setting the start 
  Color end(endColor, endParam); // Setting the end

  // At this point I am not very comfortable =)

  // Declaration of class specific functions
  int range(int); 
  int newRGB(int); 

};

// RGB class function definitions
int RGB::range(int obj) // obj = red, green, blue or param
{
  // Calculating the range between max and min values
  // This is where I want to pick up the variables set
  // in the Color() constructor
  return (end.obj - start.obj);
}

int RGB::newRGB(int obj) // obj = red, green or blue (not praram)
{
  // Calculating the new red, green or blue
  // Again need to pick up variables from Color() constructor
  return (end.obj - ((1 - factor(currentValue)) * range(obj)));
}


// ========== MAIN ==========
int main()
{
  // some coding goes here

  return 0;
}


// ========== FUNCTIONS ==========
// External (friend) function definitions 
int factor()
{
  // Calculating factor (interpolation)
  // CurrentValue is on the todo list
  return (currentValue - start(value)) / range(value);
}

unsigned long dynamicColor()
{
  // Converts the new colors into hex format
  // At this point red, green and blue should tell where to look for
  // the needed values. 
  return (((newRGB(red) << 16) & 0xFF) \
	  + ((newRGB(green) << 8) & 0xFF) \
	  + (newRGB(blue) & 0xFF));
}

Last edited by mikaelbrun (2016-11-20 11:56:51)

Offline

#9 2016-11-20 16:43:28

mpan
Member
Registered: 2012-08-01
Posts: 1,188
Website

Re: [SOLVED]Need help understanding friendship with classes (C++)

Programs like that are not the best place to learn object-oriented programming. Below some level of complexity OOP just doesn’t work and produces ridiculous code. See the size of my class compared to your original code, to notice what I’m talking about.

As for the code you have presented above, any analysis ends in line 39. You have global variables there. This is it, this is the end — below this line it may be safely assumed that something will be broken in the code, and the break is unfixable.

Taking the above assumption into consideration and just skimming over the source:

  • What does Color represent? The name suggests a color, but there is some strange value field and it takes something related to “temperature, wifi-connection, ...” — so certainly not a color.

  • The Color class does nothing. It has no methods to work on its data, so at this point you can safely drop all the fields — they just waste space. Since there will be neither methods nor fields, you can as well remove the whole class.

  • You store packed RGB value in an int (parameter to Color constructor) instead of a type that has at least 24 bits, like ::std::uint_least32_t or unsigned long. Also, what’s the point of passing packed RGB into the constructor instead just passing red, green and blue colors separately?

  • Why do you re-define Color constructor, if there is nothing to do for the destructor? Not only you introduce confusion and add yourself work, but actually your destructor is worse compared to the default one.

  • Not an error, but void in arguments list is optional for C++ — this is not C wink.

  • Don’t put comments just to put comments. Everyone knows that derived class is a derived class just by looking at the code, because this is what language syntax tells us.

  • I don’t really get what RGB class does.

  • Some comments are more than confusing. “converts the new colors into hex format” — not only the function refers to non-existing variables and functions, but it doesn’t make a hexadecimal representation of a number (it would return ::std::string then, as hexadecimal representation is a textual format) as described by the comment. Instead it contains something that looks like an attempt to store a RGB value packed into 24 bits, but a failed one, since the first two expressions are always 0.

First describe what you want to do, only then try to code it or ask if the code is right. Right now for me everything looks like a set of random thoughts that don’t form anything particular.

What kind of help are you expecting? Right now I’m assuming that you’re following some OOP course and want comment on the code, but the last code seems more like you wanted to ask how to start that in the first place.

Last edited by mpan (2016-11-20 16:58:21)


Sometimes I seem a bit harsh — don’t get offended too easily!

Offline

#10 2016-11-22 08:08:34

mikaelbrun
Member
From: Tistedal/ Norway
Registered: 2016-01-01
Posts: 43

Re: [SOLVED]Need help understanding friendship with classes (C++)

mpan wrote:

Programs like that are not the best place to learn object-oriented programming. Below some level of complexity OOP just doesn’t work and produces ridiculous code. See the size of my class compared to your original code, to notice what I’m talking about.

I see that, and think that this program might have been best writing in bash with sed/ awk, but since I want to learn C++, I thought this might be a ok assignment to practice. I was saticefied with my original program, but didn't have any projects that I could expand my knowledge of C++. That's why I started with some more complex programming to this, even though it's overkill.

mpan wrote:

Don’t put comments just to put comments. Everyone knows that derived class is a derived class just by looking at the code, because this is what language syntax tells us.
...
Some comments are more than confusing. “converts the new colors into hex format” — not only the function refers to non-existing variables and functions, but it doesn’t make a hexadecimal representation of a number (it would return ::std::string then, as hexadecimal representation is a textual format) as described by the comment. Instead it contains something that looks like an attempt to store a RGB value packed into 24 bits, but a failed one, since the first two expressions are always 0.

I know I have more comments than I actually need, but I have problems systemizing the information in my head, so it is added for myself to help me navigate and connect the dots. Sometimes when I read other codes, I find it hard to visualize the connection between functions, classes, pointers and so on.

mpan wrote:

What kind of help are you expecting? Right now I’m assuming that you’re following some OOP course and want comment on the code, but the last code seems more like you wanted to ask how to start that in the first place.

First of all I just need to understand what the example I had meant, and then things expanded.

I find your harshness very welcome, since you discribe your issues so well, and gives me good advice at the same time.
I will reconsider my program, and try to start over with a better plan on how to accomplish what I want. There are still some features I need more time to understand, and will focus on this in small steps before I get back to you smile
I also need to practice my nameing of variables, functions, classes ...
Thanks very much, mpan, and all of you replied here.

Offline

Board footer

Powered by FluxBB