Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- //Main.cpp
- //
- #include <iostream>
- using namespace std;
- #include "Person.h"
- int main(){
- Person P(25, "Bob");
- }
- //
- //Person.cpp
- //
- #include "Person.h"
- #include <string>
- using namespace std;
- #include <iostream>
- Person::Person(int age1, string name1)
- : name(name1), age(age1) //Error on age: "'age' is not a nonstatic data member or base class of class 'Person'"
- {
- }
- void Person::DisplayFacts(){
- cout << name << "'s age is " << age << endl; //Same error here when accessing age.
- }
- Person::~Person(void){
- }
- //
- //Person.h
- //
- #ifndef Person_H
- #define Person_H
- #pragma once
- #include <string>
- using namespace std;
- #include <iostream>
- class Person{
- public:
- Person(int age1, std::string name1);
- ~Person(void);
- void DisplayFacts(void)
- private:
- int age;
- string name;
- };
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement