这似乎是一个常见的问题。我在classA中定义了一个枚举,然后在classB中包含了classA。然后,在 classB 中,我定义了一个函数,该函数返回 classA 中定义的枚举类型......见下文。我收到以下错误:
aFirst.obj:错误 LNK2019:函数 _wmain 1>C 中引用的未解析的外部符号“public: enum justEnum::things_t __thiscall usesTheEnum::returnsThings(void)”(?returnsThings@usesTheEnum@@QAE?AW4things_t@justEnum@@XZ) :\Documents and Settings\Ben\My Documents\Visual Studio 2010\Projects\aFirst\Debug\aFirst.exe : 致命错误 LNK1120: 1 unresolved externals
#pragma once
class justEnum
{
public:
justEnum(void);
~justEnum(void);
enum things_t{ONE, TWO};
};
#pragma once
#include "justEnum.h"
class usesTheEnum
{
public:
usesTheEnum(void);
~usesTheEnum(void);
justEnum::things_t returnsThings(void);
};
#include "StdAfx.h"
#include "usesTheEnum.h"
#include "justEnum.h"
usesTheEnum::usesTheEnum(void)
{
}
usesTheEnum::~usesTheEnum(void)
{
}
justEnum::things_t returnsThings()
{
return justEnum::ONE;
}
// tester.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <stdio.h>
#include <iostream>
#include "justEnum.h"
#include "usesTheEnum.h"
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
usesTheEnum aUser;
justEnum anEnum;
justEnum::things_t anotherEnum;
anotherEnum = justEnum::ONE;
aUser.returnsThings();
cout << anotherEnum;
return 0;
}