Design of C ++ prime + repeated virtual functions

Source: Internet
Author: User

# Include <string>
# Include <iostream>
Using namespace STD;

Class worker {
Public:
Int ID;
String name;
Worker (INT id1 = 0, string name1 = "", float salary1 = 0.0): ID (id1), name (name1), salary (salary1 ){}
Virtual void get_salary (int id)
{
Cout <salary <Endl;
}
Protected:
Float salary;
};

Class TEM: public worker {
Public:
TEM (INT id1 = 0, string name1 = "", float salary1 = 0.0, int level1 = 0): worker (id1, name1, salary1), level (level1 ){}
Void get_salary (int id) = 0;
Protected:
Int level;
};

Class worker_d: Public TEM {
Public:
Worker_d (INT id1 = 0, string name1 = "", float salary1 = 0.0, int level1 = 0): TEM (id1, name1, salary1, level1 ){}
Void get_salary (int id)
{
Cout <id <"<level <" "<salary;
}

};

# Include "worker. H"

Int main ()
{
Worker A (0, "Vivi", 3000 );
Worker_d B (1, "Cucu", 1 );
Tem c (2, "Cucu", 1 );
A. get_salary (0 );
B. get_salary (1 );
}

G ++-O main. cpp

Main. cpp: In function 'int main ()':
Main. cpp: 7: Error: cannot declare variable 'C' to be of abstract type 'tem'
Worker. h: 18: Note: because the following virtual functions are pure within 'tem ': // pure virtual function
Worker. h: 21: Note: Virtual void TEM: get_salary (INT)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.