2009-10-06 54 views
0

我在头文件中写了函数体,所以没有源文件。当我试图在Visual Studio中运行我的项目。我得到了一个没有源文件的头文件

error: Cannot open source file: No such file or directory. 

如何使视觉工作室了解到,该函数的定义是头本身内?

+0

你*有*至少有一个源文件,对不对? 'main'必须位于源文件中。 – rlbond 2009-10-06 19:21:01

回答

3

您需要创建一个仅仅包含的#include“source.h”

编辑虚拟source.cpp文件 - 我只是尝试这样做 - Visual Studio将让你做。

TEST.CPP

#include "test.h" 

其中test.h

#include "stdio.h" 
int main() 
{ 
    printf("hello world"); 
    return 0; 
} 

有趣的 - 但毫无意义!

+0

你不需要这样做。您可以简单地通过在头文件中创建它们来内联函数。这里还有其他的根本错误。 – wheaties 2009-10-06 19:15:35

+1

我猜这是他项目中唯一的文件。 VS不会建立只有头文件的项目。 – 2009-10-06 19:28:29

+0

可以在头文件中放置各种东西,但除非至少有一个源文件,否则Visual Studio将不编译任何东西。 (顺便说一下,函数不在头文件中内联,它们通过在类定义中自动内联。) – 2009-10-06 19:29:20