亲宝软件园·资讯

展开

代码重定义

SmallBlackEgg 人气:5
[toc] # 引言     重定义,简而言之就是同一个变量定义了两次或者多次。如下面的代码所示,在test.h中定义了一个类,但是我在add.h中和main.cpp中都引用了test.h文件,这时候在编译的过程中会产生错误。 # 测试代码 ```cpp /*****test.h*****/ class Test{ public: int i; }; ``` ```cpp /*****add.h*****/ #include "test.h" int Add1(int a,int b); ``` ```cpp /*****add.cpp*****/ #include #include "add.h" int Add1(int a, int b) { Test test_add; std::cout<<"This Add1 function"< #include "add.h" #include "test.h" int main() { Test test_main; std::cout<<"Run main"<

加载全部内容

相关教程
猜你喜欢
用户评论