所以我一直坚持从一个类到另一个类共享一个函数的问题,而我找到的每个解决方案都没有解决我的问题.这里有一个例子(我向你保证还有其他例子),[http://software.intel.com/en-us/articles/cdiag436]
Bar.h
#ifndef __Bar_h_
#define __Bar_h_
#include "BaseApplication.h"
#include <Foo.h>
class Foo;
Foo *foo;
class Bar : BaseApplication
{
public:
Bar(void);
~Bar(void);
protected:
virtual void barCreate(void);
};
#endif
Run Code Online (Sandbox Code Playgroud)
Bar.cpp
#include "Bar.h"
#include <Foo.h>
Bar::Bar(void){}
Bar::~Bar(void){}
void Bar::barCreate(void)
{
if(foo->foobar()==true) //error: pointer to incomplete class type is not allowed
{//stuff}
}
Run Code Online (Sandbox Code Playgroud)
foo.h中
#ifndef __foo_h_
#define __foo_h_
class Foo
{
public:
Foo(void);
~Foo(void);
bool foobar(void);
};
#endif
Run Code Online (Sandbox Code Playgroud)
Foo.cpp中
#include "Foo.h"
Foo::Foo(void){}
bool Foo::foobar(void){ return true; }
Run Code Online (Sandbox Code Playgroud)
如果我能得到一些指示或解释我哪里出错将会很棒.