|
-
March 15th, 2005, 10:02 AM
#4
Re: calling non-static methods statically
in this way ClassC::somefunc() should be declared as static. In 'unrelated' way it is possible to do like:
Code:
class Base
{
public:
int func();
}
class Derived: public Base
{
public:
int func();
}
class Unrelated
{
int somefunc()
{
Derived obj;
return obj.(Base::func());
}
}
As you see, it is NOT static, because function has to be called for some object ('obj' in this example). In your first example the object for which the function was called is pointed by 'this', and its possible because derrived class contains object of its base class. In your second example, ClassC::somefunc() is not called for any object, even for 'this', since 'this' cannot point to object of unrelated class ClassC.
Quite complicated
B+!
'There is no cat' - A. Einstein
Use [code] [/code] tags!
Did YOU share your photo with us at CG Members photo gallery ?
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
|