Attention: I figured it out. I forgot to change A to be c instead when I was messing around with my classes.
I'm trying to figure out how to link classes by inheritance but I keep getting an error:
Here is my sample code:Code:Line 41 | error: expected unqualified-id before '-' token
Edit: Forgot to include the methods for set, so I included those as well.
Code:#include <iostream> #define CONTACTS 50 using namespace std; class A { private: string name[CONTACTS]; public: void set_name(string, int); string get_name(int x){return name[x];} }; void A::set_name(string s, int x){name[x] = s;} class B: public A { private: string number[CONTACTS]; public: void set_number(string, int); string get_number(int x){return number[x];} }; void B::set_number(string s, int x){number[x] = s;} class C: public B { private: string email[CONTACTS]; public: void set_email(string, int); string get_email(int x){return email[x];} }; void C::set_email(string s, int x){email[x] = s;} int main(){ C c; int index = 0; c.set_name("First Last", index); c.set_number("1-234-567-8901", index); c.set_email("first.last@gmail.com", index); cout << c.get_name(index) << endl; cout << c.get_number(index) << endl; cout << c.get_email(index) << endl; return 0; }



LinkBack URL
About LinkBacks



