Error with OOP inheritence
Hy, I was reviewing OOP and got stuck on this exercise, but can't figure out what I did wrong...
In these two lines
cout << first.getAge << "\n";
cout << first.getLanguage << endl;
I gor errors:
Error C3867 'Programmer::getLanguage': non-standard syntax; use '&' to create a pointer to member learncpp
Error C3867 'Person::getAge': non-standard syntax; use '&' to create a pointer to member
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
#include <iostream>
#include <string>
using namespace std;
class Person
{
private:
string m_name;
int m_age;
public:
Person(string name = "", int age = 0): m_name(name), m_age(age)
{}
string getName() const { return m_name; }
int getAge() const { return m_age; }
};
class Programmer : public Person
{
private:
string m_language;
public:
Programmer(string name = "", int age = 0, string language = ""): Person(name, age), m_language(language)
{}
string getLanguage() const { return m_language; }
};
int main()
{
Programmer first("Joe", 22, "Python");
cout << first.getAge << "\n";
cout << first.getLanguage << endl;
return 0;
}
|
1 2 3 4 5 6 7 8
|
int main()
{
Programmer first("Joe", 22, "Python");
cout << first.getAge() << "\n";
cout << first.getLanguage() << endl;
return 0;
}
|
Good Luck !!
Oh, how did I overlook that :/ Thanks!! :)
Just one thing:
I got another error on line 5 in TheIdeasMan's post:
1. no operator "<<" matches these operands
I got another error on line 5 in TheIdeasMan's post:
1. no operator "<<" matches these operands
|
I compiled using the cpp.sh (the gear icon top right of the code) with all 3 warning levels on, and c++14. No warnings or errors, and this output:
What did you compile with? Always show error messages verbatim.
Funny, I did it in Visual studio, restarted it and now it worked. Thanks!
Topic archived. No new replies allowed.