Currently, I am in the process of developing a C++ program that involves dealing with CSS. However, I have encountered a perplexing issue that has me completely stumped.
The problem lies within my class structure setup where I have a class called HTMLObject that inherits from another class named CSS:
struct Border {
string bottom;
string bottom_color;
string bottom_left_radius;
string bottom_right_radius;
string bottom_style;
//... many more strings
};
struct Background {
string color;
string image;
string position;
string size_;
string repeat;
string origin;
string clip;
string attachment;
};
struct Margin {
string top, right, bottom, left;
};
struct Padding {
string top, right, bottom, left;
};
class CSS {
private:
public:
string position, display, height, width;
string top, right, bottom, left;
string color;
string min_width, min_height, max_width, max_height;
string overflow, opacity, text_align, z_index;
Margin margin;
Padding padding;
Background background;
Border border;
Font font;
};
This is followed by the declaration of the CSS HTMLObject:
class HTMLObject : public CSS
{
public:
//..various members and methods
CSS css;
string GetCSS()
{
cout << "instance address: " << this << " " <<
this->css.background.image << this->css.color << " " <<
this->css.border.bottom << endl;
//more code to be added here before returning a string
}
};
Furthermore, there are additional classes that inherit from HTMLObject:
class cClass1 : public HTMLObject
{
private:
public:
cClass1() : HTMLObject("instantiated"){}
};
typedef cClass1* Class1;
Lastly, we have our main function implementation:
Class1 b = new cClass1();
b->css.color = "red";
b->css.border.bottom = "3px";
b->background.image = "-webkit-linear-gradient(#ffffff 0%, #F6F6F6 30%, #F3F3F3 45%, #EDEDED 60%, #eeeeee 100%)";
cout << "Var address:" << b << " " << b->background.image << endl << endl;
cout << b->GetCSS() << endl;
cout << "GetCSS() finished.\n";
Upon running the program, the output I'm receiving is not what I anticipated, causing some frustration on my end!
Var address: 0x55e3b0b83ae0 -webkit-linear-gradient(#ffffff 0%, #F6F6F6 30%, #F3F3F3 45%, #EDEDED 60%, #eeeeee 100%)
instance address: 0x55e3b0b83ae0 red 3px
GetCSS() finished.
In case you want to take a look at the screenshot of the output, you can do so here.
Note: I am using GCC (GNU Compiler) and faced this issue on both Ubuntu and MacOSX systems.