Advertisement
Guest User

Problem with variable age

a guest
Jun 17th, 2013
420
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.82 KB | None | 0 0
  1. //
  2. //Main.cpp
  3. //
  4. #include <iostream>
  5. using namespace std;
  6. #include "Person.h"
  7.  
  8. int main(){
  9.     Person P(25, "Bob");
  10.    
  11. }
  12.  
  13. //
  14. //Person.cpp
  15. //
  16. #include "Person.h"
  17. #include <string>
  18. using namespace std;
  19. #include <iostream>
  20.  
  21. Person::Person(int age1, string name1)
  22. :   name(name1), age(age1) //Error on age: "'age' is not a nonstatic data member or base class of class 'Person'"
  23. {
  24. }
  25.  
  26. void Person::DisplayFacts(){
  27.     cout << name << "'s age is " << age << endl; //Same error here when accessing age.
  28. }
  29.  
  30. Person::~Person(void){
  31.  
  32. }
  33.  
  34. //
  35. //Person.h
  36. //
  37. #ifndef Person_H
  38. #define Person_H
  39. #pragma once
  40. #include <string>
  41. using namespace std;
  42. #include <iostream>
  43.  
  44. class Person{
  45. public:
  46.     Person(int age1, std::string name1);
  47.     ~Person(void);
  48.     void DisplayFacts(void)
  49. private:
  50.     int age;
  51.     string name;
  52. };
  53.  
  54. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement