Hi everyone I'm new here. I just started programming in C++ and I do not seem te get my getter method working. Here is my code:
#pragma once
class Person
{
private:
std::string name;
int age;
double weight;
double height;
public:
Person();
Person(std::string _name, int _age, double _weight, double _height)
: name{ _name }, age{ _age }, weight{ _weight }, height{ _height }
{}
~Person();
std::string get_name() { return name; }
int get_age() { return age; }
double get_weight() { return weight; }
double get_height() { return height; }
};
When I try to call the get_name function I get an error, however the other getter methods work just fine.
I called the method like this:
Person *guy = new Person("Chad", 30, 70.0, 185.0);
cout << "Name = " << guy->get_name() << " Age = " << guy->get_age()<< "Weight = " << guy->get_weight() << "Height = " << guy->get_height() << endl;
But is give me the following error:
Error (active) E0349 no operator "<<" matches these operands Project2 c:\Users\Abdullah\source\repos\Project2\Project2\Source.cpp 37
The error disappears as soon as I erase the get_name() method. Does anyone have an idea why this is?