问题描述
我刚刚继承了一些旧代码。问题方法被调用的地方。我在底部有两个解决方案,但是为什么使问题方法虚拟化呢?
OtherClass::someOtherMethod() {
// problemMethod(Manager* manager,const ConfigClass* config)
obj->problemMethod(man,conf); // conf is not const in this file which therefore does not match the params list.
}
现在在obj .h和.cpp中,该方法具有以下形式(我检查cpp和h都匹配)。
problemMethod(Manager* manager,const ConfigClass* config);
尝试构建时,OtherClass :: SomeOtherMethod中有未解决的外部对象,不知道问题方法在哪里。
两个解决方案:更改.h和.cpp中的problemMethod并删除const。哪个工作,构建和运行。或将问题方法设为虚拟。为什么要使其虚拟化?我的猜测是,因为它是虚拟的,所以会延迟到运行时为止,这可以防止链接器错误,然后稍后再解决... ???关于链接器错误的令人困惑的部分是,Visual Studio在该方法上按F12键时会找到它并知道它在哪里。
解决方法
已解决:
问题在于,在OtherClass.h中,当Config是一个类时,该配置已被向前声明为结构。它没有在vs2010中抱怨这一点,但是在vs2017中对此有所抱怨