derived class objects in base class static function

C

Chris Forone

hello group,

is it possible to use derived class objects in base class static function?

example:

#include <iostream>

class b;

class a
{
public:
a() {}
virtual ~a() {}

static void Init() {b thing; thing.Do();} // compile
// error
};

class b : public a
{
public:
b() {}
virtual ~b() {}

void Do() {std::cout << "hello?" << std::endl;}
};

int main()
{
a::Init();
}

thanx & hand, chris
 
I

Ian Collins

Chris said:
hello group,

is it possible to use derived class objects in base class static function?

example:

#include <iostream>

class b;

class a
{
public:
a() {}
virtual ~a() {}

static void Init() {b thing; thing.Do();} // compile
// error

Declare the function here, define it after class b.
 
C

Chris Forone

Ian said:
Declare the function here, define it after class b.
thanx, the example works. the original code is with headers &
implementation separated and therefor not as simple...
 
C

Chris Forone

Chris said:
thanx, the example works. the original code is with headers &
implementation separated and therefor not as simple...
ok, done! ive put the #include of derived class directly after #include
of base class in base class implementation. dont know if this is best
solution... thanx a lot, chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top