(类)不命名类型
(class) does not name a type
本文关键字:类型 更新时间:2023-10-16
我正在尝试通过makefile编译一个程序。当我从命令行启动make时,编译器会给我此错误:
g++ -Wall -g -c main.cpp -std=c++11
In file included from main.cpp:9:0:
athlete.h:9:9: error: 'string' does not name a type
string name;
我已经尝试搜索,我发现一些常见问题与缺少#include <string>
、"倒置预处理器指令"、using namespace std;
使用不当或在其他头文件中#includes
使用不当有关。我试图修复这 4 点,但没有结果,也许我忽略了一些东西。希望这个问题不会让你感到厌烦。谢谢。在一些文件代码块下面(并非所有文件都包括在内(。
主.cpp
#include <iostream>
#include <fstream>
#include <ctime>
#include <iomanip>
#include <string>
#include <cstring>
#include <stdio.h>
#include <stdlib.h>
#include "athlete.h"
#include "upd_at.h"
using namespace std;
int main(){
Athlete f;
f.set_generalities();
f.set_perfind();
f = update_test_res(f);
return 0;
}
运动员
"....">的意思是:(希望(不相关的代码行。
#ifndef ATHLETE_H_INCLUDED
#define ATHLETE_H_INCLUDED
//declarations of Athlete
class Athlete{
private:
//generalities
string name;
int age;
int height;
double weight;
int tr_exp;
....
public:
....
};
#endif // ATHLETE_H_INCLUDED
运动员.cpp
void Athlete::set_generalities(){
string in_name;
int in_age;
int in_height;
double in_weight;
int in_tr_exp;
....
}
void Athlete::set_perfind(){
int in_RHR, in_maxHR;
double in_1rmsq, in_1rmbp, in_1rmcl, in_1rmdl, hndgrp;
....
return ;
}
//create a first txt with athlete generalities and tests column
void create_ath_file(){
// current time/date based on current system
time_t now = time(0);
tm *ltm = localtime(&now);
const char* name_pt = name.c_str();
ofstream myfile;
myfile.open(name_pt);
....
myfile.close();
}
生成文件
p1: main.o upd_athlete.o athlete.o
g++ -Wall -g main.o upd_athlete.o athlete.o -o p1 -std=c++11
main.o: main.cpp athlete.h athlete.cpp upd_at.h upd_athlete.cpp
g++ -Wall -g -c main.cpp -std=c++11
upd_athlete.o: upd_athlete.cpp upd_at.h athlete.cpp athlete.h
g++ -Wall -g -c upd_athlete.cpp -std=c++11
athlete.o: athlete.cpp athlete.h
g++ -Wall -g -c athlete.cpp -std=c++11
clean:
rm *.o
您需要:
-
在athlete.h
中使用using namespace std;
-
在#include "athlete.h"
之前将using namespace std;
移入main.cpp
现在这些只是非常糟糕的黑客。
- 有资格
string
-std::string name
在athlete.h
.std::
在我们打字时并不难打字,所以我不会在任何地方使用using namespace std;
。
此外,您应该将适当的标准标头直接#include
到athlete.h
,否则您只是依靠用户和athlete.cpp
在athlete.h
包含之前这样做。
使用 std::string 而不是 string。
相关文章:
- ArduinoJson 6.15.2:JsonObject没有命名类型
- 防止主数据类型C++的隐式转换
- 大量序列中核苷酸类型的快速计数
- 如何从C++中的依赖类型中获得它所依赖的类型
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- 是否可以初始化不可复制类型的成员变量(或基类)
- 如何获取std::result_of函数的返回类型
- 从父命名空间重载类型
- 如果C++类在类方法中具有动态分配,但没有构造函数/析构函数或任何非静态成员,那么它仍然是POD类型吗
- 我想将一个对T类型的非常量左值引用绑定到一个T类型的临时值
- Openssl 1.1.1d无效使用不完整的类型"struct dsa_st"
- 访问者访问变体并返回不同类型时出错
- 在VS2010-VS2015下编译时,如何使用decltype作为较大类型表达式的LHS
- 处理小于cpu数据总线的数据类型.(c++转换为机器代码)
- C++ 雷神库 - 使用资源加载器类时出现问题(不命名类型)
- 模板元程序查找相似的连续类型名称
- 是否可以从int转换为enum类类型
- 构造函数正在调用一个使用当前类类型的函数
- 我应该使用什么来代替void作为变体中的替代类型之一
- 类中的字符串不命名类型