Jump to content
  • Advertisement
Sign in to follow this  
zappernapper

simple constructor

This topic is 4540 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i'm sure it's something really stupid, but i need a fresh pair of eyes
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
        };
...

the compiler says that it can't find a match for sRect::sRect() what am i not seeing?

Share this post


Link to post
Share on other sites
Advertisement
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?

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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:


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.

Share this post


Link to post
Share on other sites
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++.

Share this post


Link to post
Share on other sites
Quote:
Original post by rip-off
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++.


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.

Share this post


Link to post
Share on other sites
Quote:
Original post by SeeJay
Quote:
Original post by rip-off
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++.


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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!