ISO C++ forbids declaration of * with no type

error: ISO C++ forbids declaration of 'XXXX' with no type

 

出现这个错误,一般是由于两个CPP相互都相互包含了对方的头文件造成的,比如:

 

当mainwindow.cpp、configdialog.cpp两个文件,分别包含了对方的头文件,并且分别又在自己的类中生命了对象,即:

 

mainwindow.cpp

#include "configdialog.h"

class MainWindow {

ConfigDialog *configDialog;

};

 

configdialog.cpp

#include "mainwindow.h"

class ConfigDialog {

MainWindow *mainWindow;

};

 

解决方法是,在生命对象的类名称前追加关键字“class”,即修改如下:

 

 

mainwindow.cpp

#include "configdialog.h"

class MainWindow {

class ConfigDialog *configDialog;

};

 

configdialog.cpp

#include "mainwindow.h"

class ConfigDialog {

class MainWindow *mainWindow;

};

转自http://www.cnblogs.com/wanghetao/archive/2012/02/20/2360588.html——[转自:http://lion3875.blog.sohu.com/152013483.html]

 

以下为自己出这个bug的非此类情况,找到后感觉自己很傻很天真

当写成员函数忘记写返回值类型的时候也会报这个错

转载于:https://www.cnblogs.com/babetterdj/p/7862233.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
抱歉,我在之前的回答中出现了错误。上面的代码中确实存在一个问题,即在检查是否存在相同分数的学生时,需要使用正确的类型`Student`来声明变量。 以下是修正后的代码: ```cpp #include <iostream> #include <vector> #include <algorithm> // 定义学生结构体 struct Student { std::string name; int score; // 重载小于运算符,用于排序 bool operator<(const Student& other) const { if (score == other.score) { return name < other.name; } return score > other.score; } }; int main() { int n; std::cin >> n; std::vector<Student> students; for (int i = 0; i < n; i++) { std::string name; int score; std::cin.ignore(); // 忽略上一行的换行符 std::getline(std::cin, name); std::cin >> score; // 检查是否已存在相同分数的学生 bool exists = false; for (const auto& student : students) { if (student.score == score) { exists = true; break; } } // 若不存在相同分数的学生,则将该学生添加到列表中 if (!exists) { students.push_back({name, score}); } } // 按照要求进行排序 std::sort(students.begin(), students.end()); // 输出结果 for (const auto& student : students) { std::cout << student.name << std::endl; } return 0; } ``` 请将以上代码保存为一个.cpp文件,然后使用C++编译器进行编译运行。输入学生信息后,程序将按照要求进行排序并输出结果。如果你仍然遇到相同的错误,请提供具体的错误信息以供进一步的帮助。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值