首页 > 编程语言 > 详细

C++学习01(编译器错误 C2504--"class":未定义基类)

时间:2021-07-26 13:24:23      阅读:19      评论:0      收藏:0      [点我收藏+]

声明基类,但从未定义过。 可能的原因:

  1. 缺少包含文件。

  2. 外部基类未通过 extern声明。

  3.  1 #pragma once
     2 #include<iostream>
     3 #include<string>
     4 using namespace std;
    
     7 #include"Boss.h"
     8 class Worker
     9 {
    10 public:
    11 virtual void showInfo() = 0;
    12 virtual string getDeptName() = 0;
    13 
    14 int m_Id;
    15 string m_Name;
    16 int m_DeptNo;
    17 };

     

  4.  1 #pragma once
     2 #include<iostream>
     3 #include<string>
     4 using namespace std;
     5 #include"Worker.h"
     6 class Boss :public Worker
     7 {
     8 public:
     9 Boss(int id, string name, int did){
    10 this->m_Id = id;
    11     this->m_Name = name;
    12     this->m_DeptNo = did;
    13 }
    14 
    15 virtual void showInfo(){
    16 cout << "职工编号: " << m_Id
    17         << "\t职工姓名: " << m_Name
    18         << "\t所在部门: " << getDeptName()
    19         << "\t金字塔的顶端" << endl;
    20 }
    21 virtual string getDeptName(){
    22 return string("总裁");
    23 }
    24 };
     1 #pragma once
     2 #include<iostream>
     3 using namespace std;
     4 #include<string>
     5 #include"Worker.h"
     6 //#include"Boss.h"
    #include"Boss.h"

    7 8 void test(){ 9 int id; 10 string name; 11 int dno; 12 cout << "请输入职工的编号" << endl; 13 cin >> id; 14 cout << "请输入职工姓名" << endl; 15 cin >> name; 16 cout << "请选择职工岗位" << endl; 17 cin >> dno; 18 Worker* worker = new Boss(id, name, dno); 19 cout<<"职工编号:"<<worker.m_ID<<endl; 20 } 21 //不包含就会报错 22 int main(){ 23 test(); 24 system("pause"); 25 return 0; 26 }

    把头文件#include"Boss.h"包含一下就OK了。

     

C++学习01(编译器错误 C2504--"class":未定义基类)

原文:https://www.cnblogs.com/zhangxiaobai88126/p/15060438.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!