Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Problem with variable age

By: a guest on Jun 17th, 2013  |  syntax: C++  |  size: 0.82 KB  |  views: 275  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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
clone this paste RAW Paste Data