当函数是同一程序集的一部分时,C ++无法解析的令牌错误 [英] C++ unresolved token error when function is part of the same assembly

查看:60
本文介绍了当函数是同一程序集的一部分时,C ++无法解析的令牌错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始使用C ++语法,并构建了一个非常简单的代码来进行测试:

我有以下文件:

shoe.h(包含"TieLaces"的声明)
test.cpp(包含"main")
shoe.cpp(包含在"test.cpp"中使用的函数"TieLaces")

Test.cpp和shoe.cpp是同一程序集的一部分(即shoe.cpp不是外部库的一部分).

我正在使用MS VC ++2008.它可以很好地编译,但是链接器部分报告了有关函数"TieLaces"的未解决的令牌".

我知道外部库必须在链接器配置"部分中引用外部库,但是无法引用内部函数(我知道).那么,为什么会发生此错误?

Shoe.cpp:

I am just getting used C++ syntax and have constructed a very simple bit of code for testing:

I have the following files:

shoe.h (contains declaration for "TieLaces")
test.cpp (contains "main")
shoe.cpp (contains a function "TieLaces" which I make use of in "test.cpp")

Test.cpp and shoe.cpp are part of the same assembly (i.e., shoe.cpp is not part of an external library).

I am using MS VC++ 2008. It compiles fine, but the Linker section reports an "unresolved token" with regard to function "TieLaces".

I know that external libraries must be referenced in the Linker config section for external libs, but there is no way to reference an internal function (that I know of). So, why is this error occurring?

Shoe.cpp:

#include "stdafx.h"
#include "Shoe.h"

#define TRUE 1;
#define FALSE 0;

Shoe::Shoe() {}
Shoe::~Shoe() {}

bool TieLaces(void)
{
	bool Done = TRUE;
	return Done;
}



Test.cpp:



Test.cpp:

#include "stdafx.h"
#include "Shoe.h"

using namespace System;

int main(array<System::String ^> ^args)
{
    Console::WriteLine(L"Hello World");
    Shoe newShoes;
    newShoes.TieLaces();
    return 0;
}



Shoe.h:



Shoe.h:

class Shoe
{
public:
	Shoe();
	~Shoe(void);
	bool TieLaces(void);
};

推荐答案

您已将TieLaces定义为 Shoe.h Shoe类的成员. > 但是在 Shoe.cpp 中,您已将TieLaces定义为全局函数.
更改为-
You have defined TieLaces as a member of the Shoe class in Shoe.h.
But in Shoe.cpp you have defined TieLaces as a global function.
Change it to -
bool Shoe::TieLaces(void)
{
	bool Done = TRUE;
	return Done;
}


这篇关于当函数是同一程序集的一部分时,C ++无法解析的令牌错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆