Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


Why won't this compile?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 Kwizatz   GDNet+   -  Reputation: 1201

Like
0Likes
Like

Posted 30 January 2013 - 08:54 PM

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!



Sponsor:

#2 SiCrane   Moderators   -  Reputation: 9625

Like
4Likes
Like

Posted 30 January 2013 - 09:08 PM

Derived::Load() hides Base::Load(). You can bring in Base::Load() into Derived by putting a using Base::Load; in the Derived class definition.

#3 0r0d   Members   -  Reputation: 819

Like
1Likes
Like

Posted 30 January 2013 - 10:27 PM

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



#4 Kwizatz   GDNet+   -  Reputation: 1201

Like
0Likes
Like

Posted 30 January 2013 - 11:00 PM

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.



#5 swiftcoder   Senior Moderators   -  Reputation: 10230

Like
1Likes
Like

Posted 31 January 2013 - 07:02 AM

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().


Tristam MacDonald - Software Engineer @Amazon - [swiftcoding]


#6 Kwizatz   GDNet+   -  Reputation: 1201

Like
1Likes
Like

Posted 31 January 2013 - 08:28 AM

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.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS