TransWikia.com

Human::name' should be initialized in the member initialization list [-Werror=effc++]|

Stack Overflow Asked by UnicornButt on January 10, 2021

Class example I compiled and I’m getting this message on class human. New to oop, could someone explain why i’m getting this error and how to fix it?

#include <iostream>
#include <string>

using namespace std;

class Human
{
  public:
      string name;
      int age;

      void Introduce()
      {
          cout << "I am " + name << " and am ";
          cout << age << " years old" << endl;
      }
};

int main()
{
 Human firstMan;
 firstMan.name = "Adam";
 firstMan.age = 30;

 Human firstWomen;
 firstWomen.name = "eve";
 firstWomen.age = 28;

 firstMan.Introduce();
 firstWomen.Introduce();
}

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP