|
-
April 11th, 2008, 10:09 PM
#9
Re: non-virtual functions declared in class with virtual functions
 Originally Posted by Yadrif
The issue here is that the base class has no implmentation for the overloaded operator functions, only a declaration, so I don't see how they could be called by the derived object.
So I'm questioning if the declarations serve any purpose.
Thanks.
If an unimplemented function is called somewhere in your code, then a linker error would be generated. In your example, SomeInterfaceIF::operator== is never called, so there isn't an error, however in this case there is no good reason to declare the function and never define it.
One of the few examples of where it is useful to declare, but not define a method is when making a class non-copyable:
Code:
class NonCopyable
{
private:
// these don't need to be implemented
NonCopyable(const NonCopyable &);
void operator=(const NonCopyable &);
};
- Alon
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|