谷歌搜了十几分钟都没法解决的“is not a class or namespace name”错误

csdaa2010 2014-05-22 02:13:51

//Person.h
#ifndef _PERSON_H
#define _PERSON_H
class Person
{
protected:
char *chp_name;
char *chp_id;
float f_workTime;
public:
Person(char*,char*,float);
virtual void display(char*);
virtual float getWorkTime();
};
#endif


//EmployeeH.h
#ifndef _TEACHER_H
#define _TEACHER_H
#include "PersonH.h"
class Employee:public Person
{
protected:
float f_sallary;
public:
Employee(char*,char*,float,float);
~Employee();
virtual void display(char*);
//virtual float getWorkTime();
virtual float getSallary();
virtual void setSallary(float);
};
#endif



//TeacherH.h
#ifndef _TEACHER_H
#define _TEACHER_H
class Teacher
{
public:
Teacher(char*,char*,float,float);
~Teacher();
};
#endif




//ObjDefine.cpp
Employee::Employee(char* name,char* id,float workTime,float sallary):Person(name,id,workTime)
{
this->chp_id = id;//注意 这样传直很危险!!!
this->chp_name = name;
this->f_workTime = workTime;
this->f_sallary = sallary;
}
Employee::~Employee()
{
cout<<"一个雇员对象("<<this->chp_name<<")成功的被删除"<<endl;
}

//****ObjDefine.cpp(114) : error C2653: 'Teacher' : is not a class or namespace name*****
Teacher::Teacher(char* name,char* id,float workTime,float sallary):Employee(name,id,workTime,sallary):Person(name,id,workTime)
{
//此函数出现错误!!!!!
}

Teacher::~Teacher()
{
cout<<"一个教师对象("<<this->chp_name<<")成功的被删除"<<endl;
}



//enter.cpp
#include <iostream>
#include <string>
#include "PersonH.h"
#include "EmployeeH.h"
#include "TeacherH.h"
#include "StudentH.h"
using std::cin;
using std::cout;
using std::endl;

int main()
{

return 0;
}


ObjDefine.cpp中Teacher的构造函数出现 error C2653: 'Teacher' : is not a class or namespace name
...全文
510 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
usnyfree 2016-05-01
  • 打赏
  • 举报
回复
头文件顺序不对
usnyfree 2016-05-01
  • 打赏
  • 举报
回复
预编译的那个
csdaa2010 2014-05-22
  • 打赏
  • 举报
回复
引用 10 楼 xihu1364 的回复:
//teacher.h #ifndef _TEACHER_H #define _TEACHER_H class Teacher:Employee 这不是/teacher.h 怎么变成#include "TeacherH.h" 还有class Teacher:Employee 加上public吧 看着不舒服 细心点,将声明的文件全部加到定义的文件中
不好意思,疏忽了 好的,因为改了一个中午都没找出问题 ,就把可能错的代码都重写了一遍,所以才会有这么多的格式上的问题
版主大哥 2014-05-22
  • 打赏
  • 举报
回复
//teacher.h #ifndef _TEACHER_H #define _TEACHER_H class Teacher:Employee 这不是/teacher.h 怎么变成#include "TeacherH.h" 还有class Teacher:Employee 加上public吧 看着不舒服 细心点,将声明的文件全部加到定义的文件中
csdaa2010 2014-05-22
  • 打赏
  • 举报
回复
引用 7 楼 xihu1364 的回复:
你是把teacher.h 中的类定义在ObjDefine.cpp 你不加当然就不认识了
抱歉 抱歉,我重新码字漏掉了,其是有的。 昨晚太晚睡了,,刚才睡了一下

//teacher.h
#ifndef _TEACHER_H
#define _TEACHER_H
class Teacher:Employee
{
public:
	Teacher(char*,char*,float,float);
	~Teacher();
};
#endif

//ObjDefine.cpp
#include <iostream>
#include <string>
#include "PersonH.h"
#include "EmployeeH.h"
#include "TeacherH.h"
#include "StudentH.h"
using std::cin;
using std::cout;
using std::endl;
Employee::Employee(char* name,char* id,float workTime,float sallary):Person(name,id,workTime)
{
    this->chp_id = id;//注意 这样传直很危险!!!
    this->chp_name = name;
    this->f_workTime = workTime;
    this->f_sallary = sallary;
}
Employee::~Employee()
{
    cout<<"一个雇员对象("<<this->chp_name<<")成功的被删除"<<endl;
}
void Employee::display(char *idColName)
{
    cout<<"***************雇员*******************"<<endl;
    Person::display(idColName);
    cout<<"职称:";
    if(this->f_workTime<3){cout<<"助教"<<endl;}
    else if(this->f_workTime<5)cout<<"讲师"<<endl;
    else cout<<"教授"<<endl;
    cout<<"**********************************"<<endl<<endl;
}
float Employee::getSallary()
{
    return this->f_sallary;
}
void Employee::setSallary(float sallary)
{
    this->f_sallary = sallary;
}
 
//***此处报错 error C2653: 'Teacher' : is not a class or namespace name
Teacher::Teacher(char* name,char* id,float workTime,float sallary):Employee(name,id,workTime,sallary):Person(name,id,workTime)
{
     
}
csdaa2010 2014-05-22
  • 打赏
  • 举报
回复
引用 2 楼 Symfund 的回复:
你的Teacher根本没有从Employee继承过来,欲加其罪,何患无穷?
有的,只是我重新码字的时候 改了

//teacher.h
#ifndef _TEACHER_H
#define _TEACHER_H
class Teacher:Employee
{
public:
	Teacher(char*,char*,float,float);
	~Teacher();
};
#endif

//ObjDefine.cpp
#include <iostream>
#include <string>
#include "PersonH.h"
#include "EmployeeH.h"
#include "TeacherH.h"
#include "StudentH.h"
using std::cin;
using std::cout;
using std::endl;
Employee::Employee(char* name,char* id,float workTime,float sallary):Person(name,id,workTime)
{
	this->chp_id = id;//注意 这样传直很危险!!!
	this->chp_name = name;
	this->f_workTime = workTime;
	this->f_sallary = sallary;
}
Employee::~Employee()
{
	cout<<"一个雇员对象("<<this->chp_name<<")成功的被删除"<<endl;
}
void Employee::display(char *idColName)
{
	cout<<"***************雇员*******************"<<endl;
	Person::display(idColName);
	cout<<"职称:";
	if(this->f_workTime<3){cout<<"助教"<<endl;}
	else if(this->f_workTime<5)cout<<"讲师"<<endl;
	else cout<<"教授"<<endl;
	cout<<"**********************************"<<endl<<endl;
}
float Employee::getSallary()
{
	return this->f_sallary;
}
void Employee::setSallary(float sallary)
{
	this->f_sallary = sallary;
}

//***此处报错 error C2653: 'Teacher' : is not a class or namespace name
Teacher::Teacher(char* name,char* id,float workTime,float sallary):Employee(name,id,workTime,sallary):Person(name,id,workTime)
{
	
}
版主大哥 2014-05-22
  • 打赏
  • 举报
回复
你是把teacher.h 中的类定义在ObjDefine.cpp 你不加当然就不认识了
版主大哥 2014-05-22
  • 打赏
  • 举报
回复
//ObjDefine.cpp 中加上#include “teacher.h”
csdaa2010 2014-05-22
  • 打赏
  • 举报
回复
抱歉 刚才重新码子的时候漏了写继承Employee //teacher.h #ifndef _TEACHER_H #define _TEACHER_H class Teacher:Employee { public: Teacher(char*,char*,float,float); ~Teacher(); }; #endif
Fire_Lord 2014-05-22
  • 打赏
  • 举报
回复
Teacher 构造函数调用了 Employee 的构造函数,需要 Teacher 继承 Employee 才行,class 定义的时候没有继承
Symfund 2014-05-22
  • 打赏
  • 举报
回复
楼主,散分啦,40分全数归我啊!
Symfund 2014-05-22
  • 打赏
  • 举报
回复
你的Teacher根本没有从Employee继承过来,欲加其罪,何患无穷?
csdaa2010 2014-05-22
  • 打赏
  • 举报
回复
help help
PyTorch版的YOLOv5是轻量而高性能的实时目标检测方法。利用YOLOv5训练完自己的数据集后,如何向大众展示并提供落地的服务呢?   本课程将提供相应的解决方案,具体讲述如何使用Web应用程序框架Flask进行YOLOv5的Web应用部署。用户可通过客户端浏览器上传图片,经服务器处理后返回图片检测数据并在浏览器中绘制检测结果。   本课程的YOLOv5使用ultralytics/yolov5,在Ubuntu系统上做项目演示,并提供在Windows系统上的部署方式文档。 本项目采取前后端分离的系统架构和开发方式,减少前后端的耦合。课程包括:YOLOv5的安装、 Flask的安装、YOLOv5的检测API接口python代码、 Flask的服务程序的python代码、前端html代码、CSS代码、Javascript代码、系统部署演示、生产系统部署建议等。   本人推出了有关YOLOv5目标检测的系列课程。请持续关注该系列的其它视频课程,包括:《YOLOv5(PyTorch)目标检测实战:训练自己的数据集》Ubuntu系统 https://edu.csdn.net/course/detail/30793 Windows系统 https://edu.csdn.net/course/detail/30923 《YOLOv5(PyTorch)目标检测:原理与源码解析》https://edu.csdn.net/course/detail/31428 《YOLOv5(PyTorch)目标检测实战:Flask Web部署》https://edu.csdn.net/course/detail/31087 《YOLOv5(PyTorch)目标检测实战:TensorRT加速部署》https://edu.csdn.net/course/detail/32303

33,311

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 新手乐园
社区管理员
  • 新手乐园社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧