base or super-like functionality in C++?
-
I've been working in C# and Java for a while, with only a little experience in using C++, and I'm having a little trouble finding information on if there is anything like base or super in C++. If for example I have this:
class foo {
public:
virtual void myMethod() { cout << "this part is in foo" << endl; }
};class bar : public foo {
public:
void myMethod() { base.myMethod(); cout << "\tthis part is in bar" << endl; }
};Such that, base.myMethod() would perform the tasks of myMethod() in the base class, and then it would carry out the new implementation from there; is anything like this possible in C++? thanks!
Google Profile YouTube Twitter Computer Science Series: Logic (pt1) (part 2) (part 3)
-
I've been working in C# and Java for a while, with only a little experience in using C++, and I'm having a little trouble finding information on if there is anything like base or super in C++. If for example I have this:
class foo {
public:
virtual void myMethod() { cout << "this part is in foo" << endl; }
};class bar : public foo {
public:
void myMethod() { base.myMethod(); cout << "\tthis part is in bar" << endl; }
};Such that, base.myMethod() would perform the tasks of myMethod() in the base class, and then it would carry out the new implementation from there; is anything like this possible in C++? thanks!
Google Profile YouTube Twitter Computer Science Series: Logic (pt1) (part 2) (part 3)
Hi. Just use the base's name:
class bar : public foo {
public:
void myMethod() { **foo::**myMethod(); cout << "\tthis part is in bar" << endl; }
};There's no specific keyword, since C++ allows multiple inheritance and therefore it is not guaranteed that one class has one and only one base class. Regards.
Stupidity is an International Association - Enrique Jardiel Poncela
-
Hi. Just use the base's name:
class bar : public foo {
public:
void myMethod() { **foo::**myMethod(); cout << "\tthis part is in bar" << endl; }
};There's no specific keyword, since C++ allows multiple inheritance and therefore it is not guaranteed that one class has one and only one base class. Regards.
Stupidity is an International Association - Enrique Jardiel Poncela
Thanks :) ! Going back to C++ continues to remind me how different it really is from C#
Google Profile YouTube Twitter Computer Science Series: Logic (pt1) (part 2) (part 3)
-
I've been working in C# and Java for a while, with only a little experience in using C++, and I'm having a little trouble finding information on if there is anything like base or super in C++. If for example I have this:
class foo {
public:
virtual void myMethod() { cout << "this part is in foo" << endl; }
};class bar : public foo {
public:
void myMethod() { base.myMethod(); cout << "\tthis part is in bar" << endl; }
};Such that, base.myMethod() would perform the tasks of myMethod() in the base class, and then it would carry out the new implementation from there; is anything like this possible in C++? thanks!
Google Profile YouTube Twitter Computer Science Series: Logic (pt1) (part 2) (part 3)
-
I've been working in C# and Java for a while, with only a little experience in using C++, and I'm having a little trouble finding information on if there is anything like base or super in C++. If for example I have this:
class foo {
public:
virtual void myMethod() { cout << "this part is in foo" << endl; }
};class bar : public foo {
public:
void myMethod() { base.myMethod(); cout << "\tthis part is in bar" << endl; }
};Such that, base.myMethod() would perform the tasks of myMethod() in the base class, and then it would carry out the new implementation from there; is anything like this possible in C++? thanks!
Google Profile YouTube Twitter Computer Science Series: Logic (pt1) (part 2) (part 3)
To expand on Fernando's answer - you can't really have a 'base' or 'super' keyword in C++ because a C++ class can inherit from multiple non-abstract bases.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p