这个 c++ 程序没有执行什么?
What is this c++ program not executing?
我正在测试将类放在单独的文件中的概念,同时执行时出现错误。请帮忙
主文件.cpp这是主文件
#include <iostream>
#include <string>
#include "newClass.h"
using namespace std;
int main()
{
newClass obj1("mayan");
cout << obj1.doneName() << endl ;
}
newClass.h这是单独的头文件
#ifndef NEWCLASS_H
#define NEWCLASS_H
#include <iostream>
#include <string>
#include <string>
class newClass{
private:
string name;
public:
newClass(string z) ;
string doneName();
};
#endif // NEWCLASS_H
这是单独的newClass.cpp文件
#include "newClass.h"
#include <iostream>
#include <string>
using namespace std;
newClass::newClass(string z)
{
name = z ;
}
string newClass :: doneName()
{
return name;
}
您需要阅读有关C++及其编译的更多信息。阅读有关链接器的详细信息。
请注意,C++源文件是一个翻译单元,通常包含一些头文件。阅读有关预处理器的更多信息。
您最好使用std::string
而不仅仅是头文件中的string
(因为在头文件中使用using std;
是不受欢迎的(。
不要忘记在编译时启用所有警告和调试信息。使用 GCC 编译,使用g++ -Wall -Wextra -g
编译。
在实践中,在构建具有多个翻译单元的项目时,您最好使用一些构建自动化工具,例如 GNU make。
请记住,IDE 只是美化的源代码编辑器,能够运行外部工具,如构建自动化工具、编译器、调试器、版本控制系统等......您最好能够在命令行上使用这些工具。
相关文章:
- 在只读(即 const)访问器上执行结构化绑定的最佳实践是什么?
- 在 c++ 中从执行的 shell 命令获取返回状态的安全方法是什么?
- 这个编译器错误究竟希望我执行什么?
- 当再次触发信号时,从Qt插槽执行的功能被第二次调用时会发生什么?
- 是什么将程序集转换为实际可执行的材料
- 在高通六边形处理器的word32上执行水平求和的最快方法是什么
- 在 MySQL 连接器C++ API 中使用一个函数调用执行多个查询的正确方法是什么?
- 如果我在 Linux 上更改C++动态共享库,而我的可执行程序在其上使用,会发生什么
- 这个 c++ 程序没有执行什么?
- 抛出多个异常时,catch 块执行的顺序是什么,为什么?
- 当您希望在Arduino Uno编程中同时执行不同函数时,使用什么代码/语句
- C 类方法的执行时间取决于什么
- 当删除或删除[]被执行时,计算机会做什么?
- 在CUDA中使用小M的两个MXN矩阵执行矢量点产品的最快方法是什么?
- 如果默认构造函数不执行任何操作,则目的是什么
- 有什么方法可以在C++中读取文本并执行这样的代码命令吗?
- 在执行从C++中查找时,我到底缺少什么
- 当执行此代码中的第二个语句时,内部会发生什么
- 您可以在C 中使用BOOL和INT操作员执行什么操作
- 我应该执行什么形式的测试