在C++中收到错误消息
Getting an error message in C++
我是C++新手(我是C程序员),所以如果这看起来像是一个愚蠢的问题,我深表歉意。
当我运行此程序时,我收到以下错误消息:
错误 C2661:"学生::学生":没有重载函数占用 2 个参数
我评论了错误发生的位置(2 个实例)。谢谢。
//Definition.cpp
#include "Student.h"
Student::Student(string initName, double initGPA) //error here and in main.cpp
{
name = initName;
GPA = initGPA;
}
string Student::getName()
{
return name;
}
double Student::getGPA()
{
return GPA;
}
void Student::printInfo()
{
cout << name << " is a student with GPA: " << GPA << endl;
}
//student.h
#include <string>
#include <iostream>
using namespace std;
class Student
{
private:
string name;
double GPA;
public:
string getName();
double getGPA();
void setGPA(double GPA);
void printInfo();
};
//main.cpp
#include <iostream>
#include "Student.h"
int main() {
Student s("Lemuel", 3.2); //here is the error
cout << s.getName() << endl;
cout << s.getGPA() << endl;
cout << "Changing gpa..." << endl;
s.setGPA(3.6);
s.printInfo();
return 0;
}
未声明构造函数。
试试这个:
class Student
{
private:
string name;
double GPA;
public:
Student(string initName, double initGPA);
string getName();
double getGPA();
void setGPA(double GPA);
void printInfo();
};
相关文章:
- C++错误消息*成员参考.**初学者*
- 如何通过参数抛出错误消息
- glad 导致 glfwSwapBuffers 返回错误消息
- FindPackageHandleStandardArgs.cmake:137 的 CMake 错误(消息):找不到 Boost (缺少:正则表达式)(找到合适的版本"1.72.0",
- 如何接受 [ENTER] 键作为无效输入并发送错误消息
- 重新定义预定义的 errno 错误消息 (E2BIG)
- SDL 映像:无法打开映像,仅显示错误消息
- 错误消息:使用"string* +="后"no match for 'operator+='"
- 错误消息"expected expression"....有人知道它为什么这么说吗?
- 在 Eclipse: "error: no match for 'operator='" 中获取错误消息
- GCC 警告和 gcc 错误消息之间的区别
- 为 c++ cin 上的输入数无效生成错误消息
- 来自带有mbedtls TLS的Mongoose Web服务器的错误消息
- 如何使用realsense摄像头调试ROS错误消息
- C++ 概念 - 需要括号中的概念会导致 2 条冲突的错误消息
- 编译器收到错误消息(textc.exe已停止)
- 结构数组的构造函数错误,错误消息:没有构造函数实例与参数列表匹配
- 使用 c++/WinRT Direct3D UWP Game DR 模板 Direct X11 的错误消息
- max_element() 给出非常奇怪的错误消息
- 不断收到错误消息,并非所有控制路径都返回值