static storage class error.

S

shan_rish

Hello Group,

Please go through the program below:

RatingComponent.h
=================

class RatingComponent
{
public:

static RatingComponent & getInstance();
protected:

private:

static RatingComponent * _instance;

RatingComponent(); // We're a singleton
};

RatingComponent.cpp
===================

static RatingComponent * RatingComponent::_instance = 0;

RatingComponent & RatingComponent::getInstance()
{
if ( 0 == RatingComponent::_instance )
{
RatingComponent::_instance = new RatingComponent();
}
return *(RatingComponent::_instance);
}


I am getting an error:
Error 566: "RatingComponent.cpp", line 13 # static class member
"RatingComponent *RatingComponent::_instance" may not have
this storage class.

I am using aCC 3.65 compiler from HP. The curious thing is, when i use
older version of aCC 3.55, i am not getting this
error. Any help is greatly apprecited and thanks in advance.

Cheers
Shan
 
S

shan_rish

Gianni said:
^^^^^^^^^

loose the "static" here.

Thanks for the reply. Can you please let me the know the reason for not
using static? Since i got no error when i used the earlier compiler
version. My understanding of using the static is to enforce a single
instant of the class RatingComponent.
Thanks again.

Cheers
Shan
 
G

Gianni Mariani

Thanks for the reply. Can you please let me the know the reason for not
using static? Since i got no error when i used the earlier compiler
version. My understanding of using the static is to enforce a single
instant of the class RatingComponent.

The earlier version of the compiler was wrong to not reject the code.

The meaning of "static" outside a class is different to the meaning
inside a class.
 
R

Ron Natalie

Thanks for the reply. Can you please let me the know the reason for not
using static? Since i got no error when i used the earlier compiler
version. My understanding of using the static is to enforce a single
instant of the class RatingComponent.
Thanks again.

Static is one of the keywords abused in C++. The meaning of
the word static to declare a static member only gets used inside a class
definition. Similarly, you don't repeat virtual outside the class
definition.

static outside of a class member declaration has a completely
different (albeit deprecated meaning) for data objects.
 
S

shan_rish

Ron said:
Static is one of the keywords abused in C++. The meaning of
the word static to declare a static member only gets used inside a class
definition. Similarly, you don't repeat virtual outside the class
definition.

static outside of a class member declaration has a completely
different (albeit deprecated meaning) for data objects.

Thanks to everybody who replied to my post.

Cheers
Shan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top