You are not logged in.
Pages: 1
#include <iostream>
struct base
{
void func1() { std::cout << "base::func1" << std::endl;
void func2() { func1(); }
};
struct inherited : public base
{
void func1() { std::cout << "inherited::func1" << std::endl; }
};
This is probably a pretty stupid question, but I have absolutely no clue how to do this. I'm trying to get inherited::func2 to call inherited::func1 instead of base::func1 without defining inherited::func1. This really is a conceptualised version of what I'm trying to accomplish, but it explains it well enough.
I'm using the latest version of the GCC with the experimental C++0x support.
Last edited by RetroX (2010-08-21 16:08:13)
Offline
I tried that, and the output was base::func1.
Really, what I'm trying to do is avoid repeating code. But it seems likely that I'll have to at this point.
Last edited by RetroX (2010-08-20 02:59:41)
Offline
Ahhh, I see what you're trying to do. Someone more familiar with C++ than I might be able to tell you how to muck with vtables to get inherited.func1() called instead of base.func1() (if its even possible).
Last edited by falconindy (2010-08-20 03:02:24)
Offline
#include <iostream>
struct base
{
virtual void func1() { std::cout << "base::func1" << std::endl;
void func2() { func1(); }
};
struct inherited : public base
{
virtual void func1() { std::cout << "inherited::func1" << std::endl; }
};
Last edited by PirateJonno (2010-08-20 07:09:06)
"You can watch for your administrator to install the latest kernel with watch uname -r" - From the watch man page
Offline
You only need the virtual in the base struct, not the inherited.
Offline
Yeah, I seem to have gotten it to work. For whatever reason, I thought that I already tried that, but it didn't work.
Either way, thanks!
Offline
You're welcome.
@Allan: True, I just prefer being explicit about it.
"You can watch for your administrator to install the latest kernel with watch uname -r" - From the watch man page
Offline
Plese don't use "C/C++". Your question was about C++ and nothing to do with C.
Offline
Plese don't use "C/C++". Your question was about C++ and nothing to do with C.
I've never personally used C, so, I didn't know if it applied to C or not. Sorry about that.
Offline
Pages: 1