C
Capstar
Hi NG,
I have the following code:
/* example.h */
class foo_base
{
public:
virtual ~foo_base();
protected:
foo_base();
};
class bar_base
{
public:
virtual ~bar_base();
virtual void do_something(foo_base *object) = 0;
protected:
bar_base();
};
class foo : public foo_base
{
public:
foo();
~foo();
};
class bar : public bar_base
{
public:
bar();
~bar();
void do_something(foo_base *object);
};
/* example.cpp */
#include <iostream>
using namespace std;
#include "example.h"
foo_base::foo_base()
{
cout << "constructing foo_base object" << endl;
}
foo_base::~foo_base()
{
cout << "destructing foo_base object" << endl;
}
bar_base::bar_base()
{
cout << "constructing bar_base object" << endl;
}
bar_base::~bar_base()
{
cout << "destructing bar_base object" << endl;
}
foo::foo()
{
cout << "constructing foo object" << endl;
}
foo::~foo()
{
cout << "destructing foo object" << endl;
}
bar::bar()
{
cout << "constructing bar object" << endl;
}
bar::~bar()
{
cout << "destructing bar object" << endl;
}
void bar::do_something(foo_base *object)
{
cout << "doing something with a foo_base object," << endl;
cout << "but I would like to do something with a foo object" << endl;
}
int main(void)
{
foo F;
bar B;
B.do_something(&F);
return 0;
}
But what I realy want is to have
void bar::do_something(foo *object). I can offcourse just make this
method, but that would mean I should remove bar_base::do_something(foo
*object). But I don't want that, because I want every derived class of
bar_base to have that method with it's own derived class of foo_base.
Is this possible someway or am I going the wrong direction here?
Thanks in advance,
Mark
I have the following code:
/* example.h */
class foo_base
{
public:
virtual ~foo_base();
protected:
foo_base();
};
class bar_base
{
public:
virtual ~bar_base();
virtual void do_something(foo_base *object) = 0;
protected:
bar_base();
};
class foo : public foo_base
{
public:
foo();
~foo();
};
class bar : public bar_base
{
public:
bar();
~bar();
void do_something(foo_base *object);
};
/* example.cpp */
#include <iostream>
using namespace std;
#include "example.h"
foo_base::foo_base()
{
cout << "constructing foo_base object" << endl;
}
foo_base::~foo_base()
{
cout << "destructing foo_base object" << endl;
}
bar_base::bar_base()
{
cout << "constructing bar_base object" << endl;
}
bar_base::~bar_base()
{
cout << "destructing bar_base object" << endl;
}
foo::foo()
{
cout << "constructing foo object" << endl;
}
foo::~foo()
{
cout << "destructing foo object" << endl;
}
bar::bar()
{
cout << "constructing bar object" << endl;
}
bar::~bar()
{
cout << "destructing bar object" << endl;
}
void bar::do_something(foo_base *object)
{
cout << "doing something with a foo_base object," << endl;
cout << "but I would like to do something with a foo object" << endl;
}
int main(void)
{
foo F;
bar B;
B.do_something(&F);
return 0;
}
But what I realy want is to have
void bar::do_something(foo *object). I can offcourse just make this
method, but that would mean I should remove bar_base::do_something(foo
*object). But I don't want that, because I want every derived class of
bar_base to have that method with it's own derived class of foo_base.
Is this possible someway or am I going the wrong direction here?
Thanks in advance,
Mark