-
July 30th, 2007, 08:33 PM
#1
C++ Newbie - Derived Class Issue
I'm doing an assignment for a C++ class and I'm having some serious issues understanding the topic. The assignment was to make a class called Employee..then make a class called Payroll that is derived from Employee. I think I am doing something wrong with my syntax but I can't figure out what it is. I have the employee class working.....but when I try to do anything with the derived class it gives a compile error. What am I doing wrong?
I know that the employee class is working and it doesn't seem to matter what I put into the payroll class (constructor or otherwise...it all gives the same error).
Here are my class declarations...
Thanks in advance!
Phil
p.s. The error I'm getting says "Unresolved External Symbol"
-------------------
class Employee{
protected:
char name[50];
char ssn[11];
char empId[5];
char hireDate[10];
public:
Employee();
Employee(char social[], char EmpId[], char HireDate[], char Name[]){
setSocial(social);
setEmpId(EmpId);
setHireDate(HireDate);
setName(Name);
}
bool setSocial(char[]);
void printSocial();
bool setEmpId(char[]);
void printEmpId();
bool setHireDate(char[]);
void printHireDate();
bool setName(char[]);
void printName();
};
class Payrollublic Employee{
protected:
float payRate;
float overtimeRate;
int hoursworked;
public:
Payroll(float rate,float overtime,int hours){
setPayRate(rate);
setovertime(overtime);
sethours(hours);
}
bool setPayRate(float);
bool setovertime(float);
bool sethours(int);
};
-
July 30th, 2007, 08:46 PM
#2
Re: C++ Newbie - Derived Class Issue
1) Please use code tags so that your post is readable.
2) Given the unreadable nature of your current post, can you at least share the EXACT SPECIFIC questions/problems you are having.
TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
2008, 2009,2010
In theory, there is no difference between theory and practice; in practice there is.
* Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
* How NOT to post a question here
* Of course you read this carefully before you posted
* Need homework help? Read this first
-
July 30th, 2007, 08:51 PM
#3
Re: C++ Newbie - Derived Class Issue
I'm sorry, this is my first post and I didn't realize that there were code tags.
Here is the class declaration posted again. The issue that I'm having is that something seems to be wrong with my derived class declaration and I can't figure out what it is. I have other examples that I've done before with smaller programs that look to me to be the exact same syntax...but they worked there and not here. I can't figure out what is different though.
Code:
class Employee{
protected:
char name[50];
char ssn[11];
char empId[5];
char hireDate[10];
public:
Employee();
Employee(char social[], char EmpId[], char HireDate[], char Name[]){
setSocial(social);
setEmpId(EmpId);
setHireDate(HireDate);
setName(Name);
}
bool setSocial(char[]);
void printSocial();
bool setEmpId(char[]);
void printEmpId();
bool setHireDate(char[]);
void printHireDate();
bool setName(char[]);
void printName();
};
class Payroll:public Employee{
protected:
float payRate;
float overtimeRate;
int hoursworked;
public:
Payroll(float rate,float overtime,int hours){
setPayRate(rate);
setovertime(overtime);
sethours(hours);
}
bool setPayRate(float);
bool setovertime(float);
bool sethours(int);
};
-
July 30th, 2007, 08:52 PM
#4
Re: C++ Newbie - Derived Class Issue
Looks fine to my (except that putting the opening brace at the end of a line is a Java convention, not C++. Braces should line up and bee on their own lint).
Again I ask, what EXACT SPECIFIC question/problem to You have??
TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
2008, 2009,2010
In theory, there is no difference between theory and practice; in practice there is.
* Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
* How NOT to post a question here
* Of course you read this carefully before you posted
* Need homework help? Read this first
-
July 30th, 2007, 09:05 PM
#5
Re: C++ Newbie - Derived Class Issue
The issue is that I'm getting the error
error LNK2019: unresolved external symbol "public: __thiscall Employee::Employee(void)" (??0Employee@@QAE@XZ) referenced in function "public: __thiscall Payroll::Payroll(float,float,int)" (??0Payroll@@QAE@MMH@Z) project5.obj
when I try to compile the project. I'm not sure what I'm doing wrong but I've tried it about 20 different ways and nothing is working.
I'm calling the Payroll class using the following:
Code:
Payroll stevesCheck(10,15,10);
-
July 30th, 2007, 09:11 PM
#6
Re: C++ Newbie - Derived Class Issue
That is not a declaration problem, it is am implementation problem. In some .cpp file your need
Code:
Employee::Employee()
{ // What to do for a default employee
}
TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
2008, 2009,2010
In theory, there is no difference between theory and practice; in practice there is.
* Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
* How NOT to post a question here
* Of course you read this carefully before you posted
* Need homework help? Read this first
-
July 30th, 2007, 09:16 PM
#7
Re: C++ Newbie - Derived Class Issue
The employee class works fine with the inline constructor that was in my header file. It isn't until I introduce the Payroll class that the error pops up. Do I need another employee constuctor for the payroll class?
-
July 30th, 2007, 09:18 PM
#8
Re: C++ Newbie - Derived Class Issue
Originally Posted by Gipionocheiyort
The employee class works fine with the inline constructor that was in my header file. It isn't until I introduce the Payroll class that the error pops up. Do I need another employee constuctor for the payroll class?
PRobably because you were calling the parameterized version of the Employee class. Simply put a call to "Employee test;" in your code, and you will see it fail. Even if you totally remove the payroll class.
This problem has nothing to do with the interface.
TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
2008, 2009,2010
In theory, there is no difference between theory and practice; in practice there is.
* Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
* How NOT to post a question here
* Of course you read this carefully before you posted
* Need homework help? Read this first
-
July 30th, 2007, 09:33 PM
#9
Re: C++ Newbie - Derived Class Issue
Ah I get it now. I had actually tried to fix that but I made a syntax error. When I switched
to [code]Employee(){}code]
it worked.
Thanks for your help!
-
July 30th, 2007, 09:36 PM
#10
Re: C++ Newbie - Derived Class Issue
Originally Posted by Gipionocheiyort
Ah I get it now. I had actually tried to fix that but I made a syntax error. When I switched
to it worked.
Thanks for your help!
Of course none of the fields of the employee are going to be initialized....
TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
2008, 2009,2010
In theory, there is no difference between theory and practice; in practice there is.
* Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
* How NOT to post a question here
* Of course you read this carefully before you posted
* Need homework help? Read this first
-
July 30th, 2007, 09:47 PM
#11
Re: C++ Newbie - Derived Class Issue
Originally Posted by TheCPUWizard
Looks fine to my (except that putting the opening brace at the end of a line is a Java convention, not C++. Braces should line up and bee on their own lint).
and all this time i thought it was a personal preference thing, hmmmm
-
July 30th, 2007, 09:51 PM
#12
Re: C++ Newbie - Derived Class Issue
Originally Posted by ka3ak
and all this time i thought it was a personal preference thing, hmmmm
So is the following:
Code:
#include<istrream>
class X {int a;int b;X():a(1),b(2){};int f(){return(a+b);}void g(int n){a-n;);void h(int m){b=m}};void main(){X x; x.f(4);x.g(10);cout<<x.f();}
TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
2008, 2009,2010
In theory, there is no difference between theory and practice; in practice there is.
* Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
* How NOT to post a question here
* Of course you read this carefully before you posted
* Need homework help? Read this first
-
July 30th, 2007, 09:56 PM
#13
Re: C++ Newbie - Derived Class Issue
Originally Posted by TheCPUWizard
So is the following:
Code:
#include<istrream>
class X {int a;int b;X():a(1),b(2){};int f(){return(a+b);}void g(int n){a-n;);void h(int m){b=m}};void main(){X x; x.f(4);x.g(10);cout<<x.f();}
and this:
Code:
class X
{
int a;
int b;
X() : a(1) , b(1)
{
}
int f( )
{
return a + b;
}
...
};
-
July 30th, 2007, 10:16 PM
#14
Re: C++ Newbie - Derived Class Issue
Just an observation, but I'm always surprise to see code from students learning programming (specially C++) to use char/char[] rather then std::string. Why do professors still teach that in Universities?
Last question was more rhetorical one.
-
July 31st, 2007, 07:23 AM
#15
Re: C++ Newbie - Derived Class Issue
Originally Posted by ka3ak
and all this time i thought it was a personal preference thing, hmmmm
It is, but I agree with the wizard that code where braces don't line up is very difficult to read to me.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|