Newsgroup: comp.lang.c++
Subject: Derived class question
From: swilks06@...
Date: Fri, 5 Jul 2013 14:15:33 -0700 (PDT)
I'm trying to create a derived class called DotctorType from a base class called PersonType. I thought I was doing everything correctly, but when I complied the code I had several IntelliSense errors to pop up. I can't see what's causing the errors. Can anyone else see what I'm doing wrong? Here is the code:
01#include <string>
02#include <iostream>
03using namespace std;
04
05class PersonType
06{
07public:
08 // Function to output the first name and the last name.
09 void print() const;
10
11 //Function to set the first name and the last name.
12 void setName(string first, string last);
13
14 //Function to return the first name.
15 string getFirstName() const;
16
17 //Function to return the last name.
18 string getLastName() const;
19
20 // Constructor to set the first name and the last name.
21 PersonType(string first="", string last="");
22
23private:
24 string firstName; // Variable to store the first name.
25 string lastName; // Variable to store the last name.
26};
27
28// Function to output the first name and the last name.
29 void PersonType::print() const
30 {
31 cout<<firstName<< " "<<lastName<<endl;
32 }
33
34 //Function to set the first name and the last name.
35 void PersonType::setName(string first, string last)
36 {
37 firstName = first;
38 lastName = last;
39 }
40
41 //Function to return the first name.
42 string PersonType::getFirstName() const
43 {
44 return firstName;
45 }
46
47 //Function to return the last name.
48 string PersonType::getLastName() const
49 {
50 return lastName;
51 }
52
53 // Constructor to set the first name and the last name.
54 PersonType::PersonType(string first, string last)
55 {
56 setName(first, last);
57 }
58
59class DotorType : public PersonType
60{
61private:
62 string drtype;
63
64public:
65 string getSpeciality() const;
66 void setSpeciality(string dtype);
67 DoctorType(string first="", string last="", string type="");
68
69};
70
71string DoctorType::getSpeciality();
72{
73 return drtype;
74}
75
76void DoctorType::setSpeciality(string dtype)
77{
78 drtype = dtype;
79}
80
81
82DoctorType::DoctorType(string first="", string last="", string type="")
83 : PersonType(string first="", string last="")
84{
85 setSpeciality(type);
86}
********And here are the errors:
Error 1 error LNK2001: unresolved external symbol _mainCRTStartup`
Error 2 error LNK1120: 1 unresolved externals
3 IntelliSense: explicit type is missing ('int' assumed) (Line 67)
4 IntelliSense: name followed by '::' must be a class or namespace name (Line 71)
5 IntelliSense: expected a declaration (Line 71)
6 IntelliSense: name followed by '::' must be a class or namespace name (Line 76)
7 IntelliSense: identifier "drtype" is undefined (Line 78)
8 IntelliSense: name followed by '::' must be a class or namespace name (Line 82)
9 IntelliSense: expected a '{' (Line 83)
10 IntelliSense: identifier "setSpeciality" is undefined (Line 85)
Subject: Derived class question
From: swilks06@...
Date: Fri, 5 Jul 2013 14:15:33 -0700 (PDT)
I'm trying to create a derived class called DotctorType from a base class called PersonType. I thought I was doing everything correctly, but when I complied the code I had several IntelliSense errors to pop up. I can't see what's causing the errors. Can anyone else see what I'm doing wrong? Here is the code:
01#include <string>
02#include <iostream>
03using namespace std;
04
05class PersonType
06{
07public:
08 // Function to output the first name and the last name.
09 void print() const;
10
11 //Function to set the first name and the last name.
12 void setName(string first, string last);
13
14 //Function to return the first name.
15 string getFirstName() const;
16
17 //Function to return the last name.
18 string getLastName() const;
19
20 // Constructor to set the first name and the last name.
21 PersonType(string first="", string last="");
22
23private:
24 string firstName; // Variable to store the first name.
25 string lastName; // Variable to store the last name.
26};
27
28// Function to output the first name and the last name.
29 void PersonType::print() const
30 {
31 cout<<firstName<< " "<<lastName<<endl;
32 }
33
34 //Function to set the first name and the last name.
35 void PersonType::setName(string first, string last)
36 {
37 firstName = first;
38 lastName = last;
39 }
40
41 //Function to return the first name.
42 string PersonType::getFirstName() const
43 {
44 return firstName;
45 }
46
47 //Function to return the last name.
48 string PersonType::getLastName() const
49 {
50 return lastName;
51 }
52
53 // Constructor to set the first name and the last name.
54 PersonType::PersonType(string first, string last)
55 {
56 setName(first, last);
57 }
58
59class DotorType : public PersonType
60{
61private:
62 string drtype;
63
64public:
65 string getSpeciality() const;
66 void setSpeciality(string dtype);
67 DoctorType(string first="", string last="", string type="");
68
69};
70
71string DoctorType::getSpeciality();
72{
73 return drtype;
74}
75
76void DoctorType::setSpeciality(string dtype)
77{
78 drtype = dtype;
79}
80
81
82DoctorType::DoctorType(string first="", string last="", string type="")
83 : PersonType(string first="", string last="")
84{
85 setSpeciality(type);
86}
********And here are the errors:
Error 1 error LNK2001: unresolved external symbol _mainCRTStartup`
Error 2 error LNK1120: 1 unresolved externals
3 IntelliSense: explicit type is missing ('int' assumed) (Line 67)
4 IntelliSense: name followed by '::' must be a class or namespace name (Line 71)
5 IntelliSense: expected a declaration (Line 71)
6 IntelliSense: name followed by '::' must be a class or namespace name (Line 76)
7 IntelliSense: identifier "drtype" is undefined (Line 78)
8 IntelliSense: name followed by '::' must be a class or namespace name (Line 82)
9 IntelliSense: expected a '{' (Line 83)
10 IntelliSense: identifier "setSpeciality" is undefined (Line 85)
via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?36492-Derived-class-question&goto=newpost
View all the progranning help forums at:
http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums
No comments:
Post a Comment