class Game
{
public:
static Game& GetInstance()
{
return game_;
}
private :
static Game game_;
Game();
};
Asked
Active
Viewed 86 times
-1

General Grievance
- 4,555
- 31
- 31
- 45

kokos___
- 1
-
Do you have a `Game Game::game_;` definition in some translation unit? I hope you know that static class objects still need to be defined. – StoryTeller - Unslander Monica Aug 02 '17 at 11:32
1 Answers
-3
Why did you put class constructor inside private section? This could be the cause of your problem. Move Game() to public segment and see what happens. Also I think the way you are trying to define and return a static value is wrong all together

HRN
- 21
- 4
-
-
Now your edit is even wronger. This is an implementation of the singleton pattern. Everything you suggest will not solve the linkage error. It will either break the pattern or introduce compiler errors. If you aren't sure, don't answer. – StoryTeller - Unslander Monica Aug 02 '17 at 11:39
-
He has commited two fatal syntax errors which should be resolved first then continue to the code itself. I know for a fact that if constructor is made private compiler gets confused and thus a handful of irrelevant errors (such as linkage errors) are reported so I told him to fix these two syntax errors and then get on with the rest of his code. So I suggest wait for him/her to fix the code and see if any problems remain. Anyhow I don't say his was of defining game_ is quite correct. – HRN Aug 02 '17 at 11:48
-
2They made no syntax errors, they omitted **one** definition that causes an ODR-violation. Whatever it is you think you know about the compiler getting confused is guesswork, [since the code can be easily fixed](http://ideone.com/AhZG67). But because you posted your wild speculations, the OP is likely to waste time making changes that will do anything besides help them. – StoryTeller - Unslander Monica Aug 02 '17 at 11:51