【发布时间】:2016-01-05 01:37:45
【问题描述】:
我正在使用 Windows 窗体应用程序 MSVS 2010 中的简单程序,突然遇到一个非常奇怪的问题:我无法在类中创建虚拟函数。
代码如下:
#pragma once;
#include <string>
using namespace std;
using namespace System;
class Reptile
{
private:
char *diet;
string title;
double weight;
int lifespan;
char sex;
public:
char* getDiet();
bool setDiet(char* newDiet);
string getTitle();
bool setTitle(string newTitle);
double getWeight();
bool setWeight(double newWeight);
int getLifespan();
bool setLifeSpan(int newLifespan);
char getSex();
void setSex(char newSex);
virtual void Show(void);
virtual void Voice(void);
~Reptile();
Reptile(); };
它会抛出这样的错误:
Reptile.obj : error LNK2028: unresolved token (0A00000E) "public: virtual void __clrcall Reptile::Voice(void)" (?Voice@Reptile@@$$FUAMXXZ) 在函数 "void __clrcall dynamic initializer for ' 中引用const Reptile::vftable'''(void)" (???__E??_7Reptile@@6B@@@YMXXZ@?A0xc2bc2ccd@@$$FYMXXZ)
我真的不知道如何处理它,因为我对 clr 和其他东西不是很熟悉。
【问题讨论】:
-
你只展示了
Voice()的声明。你也有实现吗?
标签: c++ visual-studio-2010 clr virtual