Compile error : Class X has no member Y

Hello ,

when I try to compile my code , I get the error above.

-----test.h-----

public:
int getAge();

-----test.cpp-----

int Person::getAge(){
return age;
}

-----main.cpp-----

int main(){

Person Test("Test" , 21); // name and age
Test.toString(cout);
string test =Test.getName();
cout<<"name : " << test <<endl;
return 0;
}

I am able to make an object named Test with name " test " and age =21.And also able to print the info to the output.

But when I only want the age of the object Test , I get the error "error C2039: 'getName' : is not a member of 'Person'" .

I described the function in test.h and test.cpp .

Someone has an idea of what I'm doing wrong?

Thanks in advance !
Afternoon SneakSz. Post your whole code so we can clearly see whats going on, because as far as i can see you haven't defined GetName() in person (because you haven't posted it). If its not there, there's not much i can do to help.


Oh, and use code blocks when posting code for better readability
Ok

Person.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include <string>
using namespace std;

class Person {
private:
	string name;
	int age;
	double budget, successRate;

public:
	Person();
	Person(string I_name, int I_age);
	int getAge();
	string getName();
	void toString(ostream &output);
	//friend ostream& operator<< ( ostream& uit, Person & p );

};


person.c

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

#include "Person.h"
#include <string>

Person::Person(string I_name, int I_age){
	name = I_name;
	age = I_age;
	budget = 0.0;
	successRate = 0.0;
}

Person::Person(){

	name="";
	age=0;
	budget=0.0;
	successRate = 0.0;
}
int Person::getAge(){
		return age;
	}
string Person::getName(){
		return name;
}


void Person::toString(ostream &output){
	output <<name  <<", " <<age <<" year has  " <<budget <<" EUR and " <<successRate <<" %\n";
}


Main.Cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
#include <string>
#include "Person.h"

using namespace std;

int main(){


	Person Test("Test" , 21);
	Test.toString(cout);
	string test =Test.getName();
	cout<<"name : " << test <<endl;
	return 0;
	}


Hopefully you can point me in the right direction !

Thanks in advance !

Last edited on
Topic archived. No new replies allowed.