struct sRect
{
long left;
long top;
long right;
long bottom;
sRect(const long& l, const long& t, const long& r, const long& b)
{
left = l;
top = t;
right = r;
bottom = b;
};
inline long GetVAxis()
{return (left + ((right - left) >> 1));};
inline long GetHAxis()
{return (top + ((bottom - top) >> 1));};
sPoint GetLT()
{return sPoint(left, top);};
};
...
const sRect ZERO_RECT(0,0,0,0);
...
class cObject
{
public:
cObject(const sRect& position = ZERO_RECT)
{
m_rcPos = position; // error is here
};
...
simple constructor
i'm sure it's something really stupid, but i need a fresh pair of eyes
the compiler says that it can't find a match for sRect::sRect() what am i not seeing?
There is no default constructor, though I'm not sure why that's a problem. Just adding one will probably fix it.
i gahtered it wanted a default construcotr, but it shouldn't be asking for one... i'm defining values for every call to the sRect constructor, aren't i?
instead of defining a default i jst supplied default values, but it really shouldn't have been necessary... or can someone point out why?
Prototypes for functions have semi colons after them. Your constructor is implemented, and is not a prototype. Try removing the semi colon (same goes for your other functions).
The reason is that your class has to call the default constuctor unless you tell it to do otherwise.
In your case, a default constructor won't hurt, but in general:
I've found compilers are very forgiving about stray semicolons, inside code or out in "space". Maybe its standard, I don't know, but that doest affect it. I have his code (modified) compiling here on my machine.
In your case, a default constructor won't hurt, but in general:
class cObject{ public: cObject(const sRect& position = ZERO_RECT) : m_rcPos( position ) { };...
Quote:
Prototypes for functions have semi colons after them. Your constructor is implemented, and is not a prototype. Try removing the semi colon (same goes for your other functions).
I've found compilers are very forgiving about stray semicolons, inside code or out in "space". Maybe its standard, I don't know, but that doest affect it. I have his code (modified) compiling here on my machine.
Quote:Original post by Samsonite
I didn't even know structs had default constructors , where are the tutorials on that?
A struct is a class that has default public access( and default public inheritance I think ).
Or likewise a class is a struct with default private ditto...
There are no other differences in c++.
Quote:Original post by rip-offQuote:Original post by Samsonite
I didn't even know structs had default constructors , where are the tutorials on that?
A struct is a class that has default public access( and default public inheritance I think ).
Or likewise a class is a struct with default private ditto...
There are no other differences in c++.
Really!? No differences in how they are passed (by val/ref) or in memory management as in C# either? I'm relatively new to c++ so I'm just curious.
Quote:Original post by SeeJayQuote:Original post by rip-offQuote:Original post by Samsonite
I didn't even know structs had default constructors , where are the tutorials on that?
A struct is a class that has default public access( and default public inheritance I think ).
Or likewise a class is a struct with default private ditto...
There are no other differences in c++.
Really!? No differences in how they are passed (by val/ref) or in memory management as in C# either? I'm relatively new to c++ so I'm just curious.
Nope. That is the only difference.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement