Sign in to follow this  
Kwizatz

Why won't this compile?

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
Derived::Load() hides Base::Load(). You can bring in Base::Load() into Derived by putting a [tt]using Base::Load;[/tt] in the Derived class definition.

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this