was not declared in this scope

what does it mean my age was not declared in scope?i thought I just needed to declare it in the header file.did I forgot to connect something that does not allow the cpp file to look into the header file?
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
  #include <iostream>
#include "Person.h"
#include "Student.h"
#include "Teacher.h"
using namespace std;

int main()
{
    Student obj;//first error is me missing out caps on Student
    return 0;
}

#ifndef PERSON_H
#define PERSON_H

using namespace std;
class Person
{
    public:
        Person();
        virtual ~Person();
        string first_name;
        string last_name;

        virtual void OutputIdentity();
        virtual void  OutputAge();
    protected:
        int phone;
    private:
        int age;
};

#endif // PERSON_H

#include <iostream>
#include "Person.h"
#include "Student.h"
#include "Teacher.h"
using namespace std;

Person::Person()
{
    //ctor
}

Person::~Person()
{
    //dtor
}

void OutputIdentity(){

}

void  OutputAge(){
          cout<<"i am "<<age<<" years old";
}
You forgot to write Person:: in front of the function name so the compiler thinks you're trying to define a regular function that is not part of the class.

1
2
3
4
5
6
7
void Person::OutputIdentity(){

}

void  Person::OutputAge(){
          cout<<"i am "<<age<<" years old";
}
Hello,
shouldn't obj ( quaint name ) be a Person of type class Person before it is a Student of type class Student ?

I know I was a person before I was a student but that was a long time ago
Michel Chassey
Topic archived. No new replies allowed.