Thread: Salem, why isn't this working?

  1. #1
    Registered User
    Join Date
    Dec 2019
    Posts
    99

    Salem, why isn't this working?

    Code:
    #include<iostream>
    #include<string>
    using namespace std;
    
    
    class Human
    {
        public:
            string name;
            int age;
            
            void IntroduceSelf()
            {
                cout << "I am " + name << " and am ";
                cout << age << " years old" << endl;
            }
    };
    
    
    int main()
    {
        Human firstMan;
        firstMan.name = "Adam";
        firstMan.age = 30;
        
        Human firstWoman;
        firstWoman.name = "Eve";
        firstWoman.age = 28;
        
        firstMan.IntroduceSelf();
        firstWoman.IntroduceSelf();
    }
    Code:
     error: ‘Human’ was not declared in this scope; did you mean ‘human’?   20 |         Human firstMan;
          |         ^~~~~
          |         human
    sams.cpp:21:9: error: ‘firstMan’ was not declared in this scope
       21 |         firstMan.name = "Adam";
          |         ^~~~~~~~
    sams.cpp:24:14: error: expected ‘;’ before ‘firstWoman’
       24 |         Human firstWoman;
          |              ^~~~~~~~~~~
          |              ;
    sams.cpp:25:9: error: ‘firstWoman’ was not declared in this scope
       25 |         firstWoman.name = "Eve";
          |         ^~~~~~~~~~

  2. #2
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Code:
    class Human
    Likely in the code you compiled you used "human" instead of "Human".

    If you have fixed that already delete the object files and rebuild all.

    Code:
    };
    I am only an C programmer; but, I think the ";" semi-colon is not needed.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  3. #3
    Registered User
    Join Date
    May 2012
    Location
    Arizona, USA
    Posts
    948
    It builds for me. Like stahta01 said, the code you posted here is probably different than the code you tried to build (the line numbers in the error messages don't even match the code you posted).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Salem...
    By misplaced in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 04-30-2005, 01:58 PM
  2. GJ Salem
    By Imperito in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 04-09-2002, 10:43 AM
  3. Salem this for u !
    By CFRK in forum C Programming
    Replies: 3
    Last Post: 11-30-2001, 07:06 PM

Tags for this Thread