Skip to main content
GameDev.net gamedev.net
🔒 Locked

Singleton Help

Started by tenpoundbear Mar 23, 2011 at 9:27 AM 3 replies 1.3k views
Original Post
tenpoundbear
tenpoundbear
Hey guys,

I got this set of code for a singleton class and I am getting compile errors and I am not what the problem is...
If you can look and tell me what I did wrong I be very happy

[color="#0000ff"][color="#0000ff"]
#ifndef SKY_SINGLETON_H
#define SKY_SINGLETON_H

#include <d3d9.h>
#include <d3dx9.h>
#include "Skydome.h"

class Sky_Singleton
{
public:
Sky_Singleton *getInstance();

private:
Sky_Singleton();
static Sky_Singleton *instance_sky_singleton;
SpaceObject *skydome;
};

[color="#0000ff"][color="#0000ff"]#endif


[color="#0000ff"][color="#0000ff"]
[color="#0000ff"][color="#0000ff"]#include [color="#a31515"][color="#a31515"]"Sky_Singleton.h"
Sky_Singleton* Sky_Singleton::instance_sky_singleton = NULL;
Sky_Singleton::Sky_Singleton()
{}

Sky_Singleton *Sky_Singleton::getInstance()

{

[color="#0000ff"][color="#0000ff"]if( instance_sky_singleton == NULL )

instance_sky_singleton = [color="#0000ff"][color="#0000ff"]new Sky_Singleton();

[color="#0000ff"][color="#0000ff"]return instance_sky_singleton;

}
[/source]

Error I am getting is something like this
[size="1"]error C2556: 'int *Sky_Singleton::getInstance(void)' : overloaded function differs only by return type from 'Sky_Singleton *Sky_Singleton::getInstance(void)'

[/quote]
Thanks guys... been stuck on this for few hours.

P. S. and source tags no longer work?
haegarr
haegarr
[color=#1C2837][size=2]This line
[color=#1C2837][size=2][size=2][color="#0000FF"]Sky_Singleton *getInstance();
[color=#1C2837][size=2][size=2]should probably look so
[color=#1C2837][size=2]static Sky_Singleton *getInstance();
[color="#1C2837"][size=2]

P. S. and source tags no longer work?

Use the <> button ("Insert code snippet") in the editor's tool bar.
tenpoundbear
tenpoundbear
Yeh I've tried that actually... still same errors.

I show the complete list off errors I get,


[size="1"]

error C2143: syntax error : missing ';' before '*'

error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

error C2373: 'Sky_Singleton' : redefinition; different type modifiers: see declaration of 'Sky_Singleton'

error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

error C2556: 'int *Sky_Singleton::getInstance(void)' : overloaded function differs only by return type from 'Sky_Singleton *Sky_Singleton::getInstance(void)': see declaration of 'Sky_Singleton::getInstance'

error C2371: 'Sky_Singleton::getInstance' : redefinition; different basic types: see declaration of 'Sky_Singleton::getInstance'


[/quote]

When I use the <> button... I get a WHOLE HEAP of extra tags that just messes up my code. (eg. I have cleaned up most of it but at the bottom I have left some behind to show you what I mean... it's just annoying that I have to delete the extra tags when I use that <> button).
haegarr
haegarr

Yeh I've tried that actually... still same errors.

I show the complete list off errors I get,
...

Then you don't show us all relevant stuff. Just to be sure, I've compiled the following snippet with GCC 4.2 and it compiled fine:


class SpaceObject;

class Sky_Singleton {

public:

static Sky_Singleton* getInstance();

private:

Sky_Singleton();

static Sky_Singleton* instance_sky_singleton;

SpaceObject* skydome;

};

Sky_Singleton* Sky_Singleton::instance_sky_singleton = NULL;

Sky_Singleton::Sky_Singleton() {}

Sky_Singleton* Sky_Singleton::getInstance() {
if( instance_sky_singleton == NULL )
instance_sky_singleton = new Sky_Singleton();
return instance_sky_singleton;
}

int main() {
Sky_Singleton* sky = Sky_Singleton::getInstance();
return 0;
}




When I use the <> button... I get a WHOLE HEAP of extra tags that just messes up my code. (eg. I have cleaned up most of it but at the bottom I have left some behind to show you what I mean... it's just annoying that I have to delete the extra tags when I use that <> button).

Well, the new forum software is still %&/%§ ...
Copy your code snippet and paste it as raw text into the post editor (be sure that no coloring, differing font sizes, etc occur in the editor). Then block-mark the snippet and press the <> button. That should work well when writing a post.
tenpoundbear
tenpoundbear
Thanks guys

There was an extra method that I had that seemed to be the cause of the problem. After commenting it out it compiled fine

Thanks for the copy and paste tip into notepad... I will try that next time

Very much appreciated guys

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.