Hi, I've been revising object orientated programming, and decided to have a look at accessing parts of my code in other files.
The problem is, I get error messages such as "Player1" not declared, and I can't figure out how to declare them.
For example, in my main.cpp file I have:
#include <iostream>
#include "players.hpp"
using namespace std;
int main()
{
players();
return 0;
}
And in my players.cpp I have:
#include <iostream>
#include "players.hpp"
using namespace std;
class player{
string name;
int score;
public:
void get_name();
void set_name();
};
void player::get_name()
{
cin >> name;
}
void player::set_name()
{
cout << "Player name: " << name;
}
void players()
{
player player1, player2;
cout << "Player 1 name is: ";
player1.get_name();
player1.set_name();
cout << endl;
cout << "Player 2 name is: ";
player2.get_name();
player2.set_name();
return;
}
and in players.hpp
#ifndef PLAYERS_HPP_INCLUDED
#define PLAYERS_HPP_INCLUDED
void players();
#endif // PLAYERS_HPP_INCLUDED
How would I go about using player1.name in main.cpp?
Thanks,
--Burnout.