6

Here is my main. All I am trying to do is create an object of the class file, this is probably a very noobish question so sorry, just need to know what I'm doing wrong.

#include <iostream>
#include "Player.h"

using std::cout;
using std::cin;

int main()
{
    cout << "Hello and welcome to the student adventures game.\n";

    Player player1();
}
Derek
  • 1,104
  • 13
  • 35
Benjamin-Cox
  • 129
  • 6
  • 2
    +1 because there is people who prefer to downvote over teaching. – Theraot Jul 07 '13 at 11:15
  • @Theraot: my downvote was to teach, to teach that this was a bad question. How does he detect that this object is not created? It should compile (cannot know for sure without `PLayer.h`), he doesn't ever use player1, so what's the exact error? – KillianDS Jul 07 '13 at 11:18
  • 7
    This is a duplicate and should be closed. I'm in a minority that thinks that just because something is a duplicate it shouldn't be downvoted – Armen Tsirunyan Jul 07 '13 at 11:19
  • 2
    @KillianDS thank you by explaining your downvote, was it that hard? If this was asked, it is because the asker knows no better, a downvotes alone aren't going to fix that problem. I understand that you only answer "good question", but those who ask "bad questions" are those who need more help. Also, as for not using the variable, I guess that is his take on being minimal on examples. – Theraot Jul 07 '13 at 11:23
  • @Everybody, just post your complains on meta =P – mr5 Jul 07 '13 at 12:38
  • 1
    +1 for *not* having `using namespace std` at the top of your code. – Derek Jul 07 '13 at 14:00
  • +1 For a clear and concise question, even if it does happen to be a dupe. – Code-Apprentice Jul 07 '13 at 15:06

2 Answers2

14

You declared a function which return Player type, see most vexing parse

To define an object, try update

Player player1();

to

Player player1;
billz
  • 44,644
  • 9
  • 83
  • 100
4

You shouldn't use the parenthesis when declaring an object without parameters, or else the compiler will think you're declaring a function that returns a Player and that takes no parameter.

Luchian Grigore
  • 253,575
  • 64
  • 457
  • 625
halflings
  • 1,540
  • 1
  • 13
  • 34