Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Error: MyClass& instanceToMyClass

This topic is 5305 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello I have this problem:
class Singleton<MyClass> g_MyClass; //MyClass is a singleton now

class SomeClass {
	SomeClass() {}
	~SomeClass() {}
	MyClass& m_instance_MyClass;
What I wanted was to assign "m_instance_MyClass = g_MyClass::GetInstance();" but I get the compiler error: Eroor: "SomeClass::m_instance_MyClass" must be initialized in constructor base/member initializer list. Just for the sake, I have tried to initialize it in the SomeClass() constructor... but still the same. Do the compiler want me to initialize it in the Singleton... thats absurd? Would be greatful for any help on this, thx!

Share this post

Link to post
Share on other sites
Member variable (edit) references in classes can only be initialized with member initialization lists. So what you need is something like:

SomeClass::SomeClass() : m_instance_MyClass( g_MyClass::GetInstance()) {
// whatever

But why the heck are you storing the reference to the singleton anyways?

[edited by - SiCrane on January 6, 2004 9:45:37 AM]

Share this post

Link to post
Share on other sites
Thank you, think I''ll have to read up on the member initialization list

I know I know, heh, I have changed it now... since it''s a singleton, I just use it as a global.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!