小编pre*_*215的帖子

如何将cpp和h文件链接在一起?

解决了

// Solution:
// foo.c includes foo.h; bar.c includes bar.h
g++ -Wall -Wextra -Werror -pedantic -o foobar foo.cpp bar.cpp
Run Code Online (Sandbox Code Playgroud)

我有两个cpp文件和两个h文件.我将第一个cpp链接到同名的h文件,该文件链接到链接到第二个h文件的第二个cpp文件.这是我应该将文件链接在一起的方式吗?

我的程序无效.也有错误,但我需要确保这是否是错误的一部分.这是定义/链接cpp和h文件的方法吗?

 // file: foo.cpp
 #include "foo.h"

 // file: foo.h
 #include "bar.cpp"

 #include <string>
 #include <sstream>
 #include <iostream>
 using std::cin;
 using std::cout;
 using std::cerr;
 using std::stringstream;
 using std::string;
 using std::endl;

 // file: bar.cpp
 #include "bar.h"

 // file: bar.h
 // ...
Run Code Online (Sandbox Code Playgroud)

c++

-1
推荐指数
1
解决办法
4444
查看次数

标签 统计

c++ ×1