Jump to content
  • Advertisement
Sign in to follow this  
Kwizatz

Why won't this compile?

This topic is 2089 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

class Base
{
public:
virtual bool Load()=0;
bool Load(const char* filename);
};

bool Base::Load(const char* filename)
{
/* read file to some memory buffer member */
bool success = Load();
/* close file */
return success;
}

class Derived : public Base
{
public:
bool Load();
}

bool Derived::Load()
{
/* do whatever needs to be done */
return true;
}

SomeOtherClass::Load()
{
Derived* derived = new Derived;
derived->Load("somefile");
}

I am getting a "function does not take 1 arguments" on the call to Load in SomeOtherClass::Load(), if I change the name of the Load(const char*) function to something else or I downcast the derived pointer to the base class, it does compile and links fine.

 

Same error on Visual Studio 2010 and 2012

 

Any ideas?

 

Thanks!

Share this post


Link to post
Share on other sites
Advertisement
Derived::Load() hides Base::Load(). You can bring in Base::Load() into Derived by putting a using Base::Load; in the Derived class definition.

Share this post


Link to post
Share on other sites

You might want to reconsider what you're trying to do with this code and why it's structured this way.

Share this post


Link to post
Share on other sites

Thank's SiCrane, I'll do that.

 

@0r0d: This code was a simple example of what I am doing, while the original code has to do with loading, this is not all there is to it, its not even a verbatim copy of the original code with complexity removed, explaining in detail what the original code does and why would be too lengthy a post I think, and not relevant. Suffice it to say, its part of resource loading and it is structured this way for 2 reasons: derived classes need only implement their specific resource type loading code and by keeping a data buffer inside the resource class to be filled from file or (zip compressed) memory, I avoid a (perhaps large) memcpy and releasing/using temporary buffer memory.

Share this post


Link to post
Share on other sites

Suffice it to say, its part of resource loading and it is structured this way for 2 reasons...

Neither of which give any insight into why you would use the same name for both methods.

 

It would be much simpler (and clearer to the user!) if you named the virtual method something else - LoadInternal() springs to mind, but really, anything that isn't Load().

Share this post


Link to post
Share on other sites

Yes, that's how it used to be, LoadResource which was a protected method, its a good point, I'll think about changing it to something more descriptive.

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!