Problems with inheritance!! easy code, just have some errors
Hello everyone!!
I just started learning inheritance in C++ so i tried to make a simple little example that uses inheritance but i get like 11 errros and i have no idea why!!! can someone please help me out? I'll post the code then the errors :)
Code:
//inheritance.h
//base class
class Business
{
public:
Business: itsSalary(90000),itsYears(4) {};
~Business(){};
void setSalary(long int Sal) {itsSalary = Sal;}
long int getSalary() {return itsSalary;}
void setYears(int years) {itsYears = years;}
int getYears() {return itsYears;}
protected:
long int itsSalary;
int itsYears;
};
//superset(derived class)
class Employee: public Business
{
public:
Employee(){};
~Employee(){};
void setAge(int age) {itsAge = age;}
int getAge() const {return itsAge;}
void Comment() const {cout <<"I sure do love programming!\n";}
void WakeUp() const {cout <<"Wow! I sure didn't get enough sleep!\n";}
void Sleep() const {cout <<"Goodnight!\n";}
protected:
int itsAge;
};
Code:
#include <iostream.h>
#include "inheritance.h"
int main()
{
Employee Cory;
cout <<"lets see how much money Cory gets.." << endl;
cout << Cory.getSalary << endl;
return 0;
}
Here are the errors i got:
Code:
--------------------Configuration: inheritance - Win32 Debug--------------------
Compiling...
inheritance.cpp
c:\program files\microsoft visual studio\myprojects\inheritance\inheritance.h(7) : error C2065: 'itsSalary' : undeclared identifier
c:\program files\microsoft visual studio\myprojects\inheritance\inheritance.h(7) : error C2057: expected constant expression
c:\program files\microsoft visual studio\myprojects\inheritance\inheritance.h(7) : error C2460: '.alignment member.' : uses 'Business', which is being defined
c:\program files\microsoft visual studio\myprojects\inheritance\inheritance.h(5) : see declaration of 'Business'
c:\program files\microsoft visual studio\myprojects\inheritance\inheritance.h(7) : error C2059: syntax error : 'constant'
c:\program files\microsoft visual studio\myprojects\inheritance\inheritance.h(7) : error C2143: syntax error : missing ';' before '{'
c:\program files\microsoft visual studio\myprojects\inheritance\inheritance.h(7) : error C2334: unexpected token(s) preceding '{'; skipping apparent function body
c:\program files\microsoft visual studio\myprojects\inheritance\inheritance.h(23) : error C2504: 'Business' : base class undefined
c:\program files\microsoft visual studio\myprojects\inheritance\inheritance.cpp(6) : error C2059: syntax error : 'PCH creation point'
c:\program files\microsoft visual studio\myprojects\inheritance\inheritance.cpp(7) : error C2334: unexpected token(s) preceding '{'; skipping apparent function body
c:\program files\microsoft visual studio\myprojects\inheritance\inheritance.cpp(14) : fatal error C1004: unexpected end of file found
Error executing cl.exe.
inheritance.exe - 10 error(s), 0 warning(s)
Thanks for listening :D