Error: no '__________' a member function declared in the class '_______'

I consider myself a fairly novice C ++ programmer, and I have never experienced this error before.

I'm just trying to create a class for my function, but all my std :: prefixed functions declared in my header file are not recognized

//comments
//comments
//comments
//comments
//comments
//comments
//comments
//comments
//comments
//comments
//comments
#ifndef PERSON_H
#define PERSON_H

#include <string>

class Person
{
    public:
        Person();
        std::string getName();  //return first name
        std::string getSurname();//return surname
        int getWeight();    //return weight
        int getBirthYear(); //return birthyear


    private:
//self explanatory member variables but need to be accessible to patient
        std::string m_name;
        std::string m_surname;
        int m_weight;
        int m_birthYear;
};

#endif      

.cpp

//comments
//comments
//comments
//comments
//comments
//comments
//comments
//comments
//comments
//comments
//comments
#include "Person.h"

Person::Person()
{
    m_name = "name";
    m_surname = "surname";
    m_weight = 0;
    m_birthYear = 0;
    return;
}

//returns m_name
std::string Person::getName()   
{
    return m_name;
}

//returns m_surname
std::string Person::getSurname()
{
    return m_surname;
}

//returns persnon weight
int Person::getWeight()
{
    return m_weight;
}   

//returns the person birth year
int Person::getBirthYear()
{
    return m_birthYear;
}

Main

//comments
//comments
//comments
//comments
//comments
//comments
//comments
//comments
//comments
//comments
//comments
#include "Person.h"
#include <iostream>

using namespace std;

int main()
{
//  Person matt;
//  cout << matt.getName() << endl;
//  cout << matt.getSurname() << endl;
//  cout << matt.getWeight() << endl;
//  cout << matt.getBirthYear() << endl;
    return 0;
}

And this is the error I get

g++ Main.cpp Person.h Person.cpp -o test
Person.cpp: In constructorPerson::Person()’:
Person.cpp:17:2: error: ‘m_namewas not declared in this scope
Person.cpp:18:2: error: ‘m_surnamewas not declared in this scope
Person.cpp: At global scope:
Person.cpp:35:29: error: nostd::string Person::getName()member function declared in classPersonPerson.cpp:41:32: error: nostd::string Person::getSurname()member function declared in classPerson

Any ideas what I'm doing wrong? This is the same std :: formatting worked for me before, but for some reason now only the std :: string functions are not recognized when trying to create a simple Person class.

+5
source share
1 answer

From the comments:

g++ Main.cpp Person.h Person.cpp -o test

, . , , , :

g++ -c Main.cpp Person.h Person.cpp

Main.o, Person.o, Person.h.gch. , , Person.h .

+9

All Articles