是这样的,我在类GALinearScaling.h中没有包含GAPopulation.h,只是声明class GAPopulation,因为GALinearScaling类有一个成员函数evaluate的参数为const GAPopulation.而在GAPopulation.h中包含了GAScaling.h,因为有很多地方都要用到GALinearScaling的成员函数。我是参考别人的程序这样做的。
但是编译连接时VC告诉我有以下错误:
GAPopulation.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall GALinearScaling::evaluate(class GAPopulation const &)" (?evaluate@GALinearScaling@@UAEXABVGAPopulation@@@Z)
我应该怎么修改呢?

解决方案 »

  1.   

    就是我在GALinearScaling.h文件中用到了GAPopulation类,但是我并没有包含定义GAPopulation的头文件,只是声明class GAPopulation.
    而在GAPopulation.h以及GAPopulation.cpp中都包含了GALinearScaling.h,因为有很多地方要用到GALinearScaling的成员函数。
    然后编译连接就出现了上面的错误。
    其实就是两个类之间互相引用。
    怎么修改呢?
      

  2.   

    你这样包含是不是会重复声明呢?最好用extern 在 GALinearScaling.h 中 引入 GAPopulation类这样在 GAPopulation.h 中就不会导致重复定义了。还有,如果你的GAPopulation.cpp 包含了GAPopulation.h的话,没有必要在GAPopulation.cpp中也包含GALinearScaling.h啊
      

  3.   

    在类的前面好像不能用extern
    我试了,不行
      

  4.   

    这样吧,你把你的信箱留下,我想你请教,可以发给你这几个文件。
    我已经调了好几天了,总是不行。快急死了。
    谢谢!
    我的:[email protected]