Hey all, in my program I have a Parent class Employee and a class that derives from it. In the Employee parent class I have a virtual function. In my main.cpp file I use polymorphism to create a pointer variable of class Employee and set it equal to the reference address of my derived class object. When I try and call my function using the Employee pointer it should call the function that is in my derived Class. But in the output console all I see is "lldb" and a thread break point that highlights the function in the derived class .cpp file that Im trying to call.
Heres the code incase my explanation is confusing :)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
int main(int argc, constchar * argv)
Dave d("David McMahon", 21, "Caherleaheen Tralee", 8.65);
Dave k("Kevin O Shea", 34, "Tralee", 12.45);
Employee *e = &k;
Employee(std::string n, int a, std::string addr, float s);
std::cout << "\nName of this object is: " << name << std::endl;
Dave.cpp (derived class)
1 2 3 4 5 6 7 8 9 10 11 12 13 14
Dave::Dave(std::string n, int a, std::string addr, float s): Employee(n,a,addr,s)
std::cout << "\nVirtual Function in class Dave" << std::endl; // Thread break point at this function
If anyone could help me with this error/breakpoint I would appreciate it!
Yes Im using XCode and Id say your right! :) and yes moorecm there is a Dave.h file there but seeing as its just a header file for the functions and constructors I thought Dave.cpp would be enough to post. Thanks guys! :)