• Advertisement
Sign in to follow this  

C++ declaration/definition question

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

Best way I could summarize for the title on the spot here. Consider this: A class Beta inherits from class Alpha and needs to override a function in Alpha. Here is Beta's class declaration:
class Beta : public Alpha
{
    Beta::Beta();
    ~Beta::Beta();

    void paint(CustomClass *ptrToCCObj); // this is being overridden, it's from Alpha
}
and in the definition...
void Beta::paint(CustomClass *)
{
    // some drawing code here that doesn't reference ptrToCCObj at all
}
My question is: What is being done with *ptrToCCObj? My guess is that since it's being overridden that the target class has this argument (and needs to have it when it's being overridden so it's not instead overloaded) but the inheriting class doesn't have any use for it. Is that in fact what's going on? Is there a name for this practice? Is this a hack? Thank you for your time. EDIT: Forgot to put a return type on said-class.

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by serratemplar
My guess is that since it's being overridden that the target class has this argument (and needs to have it when it's being overridden so it's not instead overloaded) but the inheriting class doesn't have any use for it. Is that in fact what's going on? Is there a name for this practice? Is this a hack?

Yes, not that I'm aware of, and no. Taking a parameter without naming it is a convenient and correct way of keeping the compiler from issuing a warning about an unreferenced parameter.

Share this post


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

  • Advertisement