Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 静态函数和链接错误_C++ - Fatal编程技术网

C++ 静态函数和链接错误

C++ 静态函数和链接错误,c++,C++,我正在使用VisualStudio,从未将中的对象文件手动链接到可执行文件 这是我的头代码: #ifndef U_H #define U_H typedef unsigned int uint; typedef unsigned short ushort; class U{ public: static uint getX(char* a, uint b, ushort c); static uint getY(char* a, uint b, ushort c);

我正在使用VisualStudio,从未将中的对象文件手动链接到可执行文件

这是我的头代码:

#ifndef U_H
#define U_H

typedef unsigned int uint;
typedef unsigned short ushort;

class U{
public:
    static uint getX(char* a, uint b, ushort c);
    static uint getY(char* a, uint b, ushort c);
    static uint getZ(char* a, uint b, ushort c);
};

#endif
和源文件:

#include "U.h"

uint U::getX(char* a, uint b, ushort c){
    //Stuff
}

uint U::getY(char* a, uint b, ushort c){
    //Stuff
}

uint U::getZ(char* a, uint b, ushort c){
    //Stuff
}
我主要包括U.h,然后使用U::getYa,b,c等调用上述函数。但是我得到以下错误:

1>main.obj : error LNK2001: unresolved external symbol "unsigned int __cdecl getX(char *,unsigned int,unsigned short)" (?getX@@YAIPEADIG@Z)
1>main.obj : error LNK2001: unresolved external symbol "unsigned int __cdecl getY(char *,unsigned int,unsigned short)" (?getY@@YAIPEADIG@Z)
1>main.obj : error LNK2001: unresolved external symbol "unsigned int __cdecl getZ(char *,unsigned int,unsigned short)" (?getZ@@YAIPEADIG@Z)

我通常会忘记源文件中的U::part,但这就是它???

这似乎是一个系统设置问题。这种事以前常发生在我身上。无论如何,请转到[Project]->[Settings]->[linker]->[enable incremental linking],查看此处的设置。上次遇到链接问题时,我将其更改为“否”,问题得到解决。

您可能忘记将u.obj链接到可执行文件。@Thomas我使用的是visual studio,以前从未手动执行过此操作?是否还有其他原因?@user997112,在VS中,您需要将您的U.cpp文件添加到解决方案资源管理器的“源文件”部分。@IvanGrynko已经在那里了-我将所有的.cpp文件都保存在“源文件”部分。您能上传一个有此问题的最小项目吗?一定是某个地方有一个坏的项目设置