【发布时间】:2016-03-31 11:39:15
【问题描述】:
我有这个错误消息
在函数'int main()'中:| 未使用的变量'Bobi' 在函数'main'中:|
对`Student::Student()'的未定义引用|
||=== 构建失败:1 个错误,1 个警告(0 分钟,1 秒)===|
你能帮我解决这个问题并检查我的方法声明
这是我的 main.cpp
#include <iostream>
#include "Student.h"
using namespace std;
int main()
{
Student *Bobi= new Student();
return 0;
}
这是我的标题
#ifndef STUDENT_H
#define STUDENT_H
#include <string>
class Student
{
public:
Student();
virtual ~Student();
std::string getName()
{
return this->name;
}
void setName(std::string name)
{
this->name=name;
}
int getNumber()
{
return this->number;
}
void setNumber(int number)
{
this->number=number;
}
std::string getSurname()
{
return this->surname;
}
void setSurname(std::string surname)
{
this->surname=surname;
}
double setDiploma1(double diploma1)
{
return this->diploma1;
}
void getDiploma1()
{
this->diploma1=diploma1;
}
double setDiploma2(double diploma2)
{
return this->diploma2;
}
void getDiploma2()
{
this->diploma2=diploma2;
}
double setIzpit1(double izpit1)
{
return this->izpit1;
}
void getIzpit1()
{
this->izpit1=izpit1;
}
double setIzpit2(double izpit2)
{
return this->izpit2;
}
void getIzpit2()
{
this->izpit1=izpit2;
}
double Bal(double setDiploma1,double setDiploma2,double setIzpit1,double setIzpit2)
{
double bal=setDiploma1+setDiploma2+setIzpit1+setIzpit2;
return bal;
}
protected:
private:
int number;
std::string name;
std::string surname;
double diploma1;
double diploma2;
double izpit1;
double izpit2;
};
#endif // STUDENT_H
Student.cpp
#include "Student.h"
#include <iostream>
using namespace std;
Student::Student()
{
}
Student::~Student()
{
}
【问题讨论】:
-
你用来编译它的 makefile 或命令是什么?
-
你如何构建你的项目?您确定使用
Student.cpp源文件构建吗?它必须在 IDE 的 project 中,而不仅仅是在磁盘上的目录中。 -
它在我的 IDE 项目中
-
我构建它然后运行它。
-
在尝试构建时不要谈论您当前的错误,但是为什么您的
set函数没有任何参数?您将班级成员设置为自身...有点奇怪,不是吗?