473,327 Members | 1,952 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

static storage class error.

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

Nov 27 '06 #1
5 1144
sh*******@yahoo.com wrote:
....
RatingComponent.cpp
===================

static RatingComponent * RatingComponent::_instance = 0;
^^^^^^^^^

loose the "static" here.
>
Nov 27 '06 #2
Gianni Mariani wrote:
sh*******@yahoo.com wrote:
...
RatingComponent.cpp
===================

static RatingComponent * RatingComponent::_instance = 0;
^^^^^^^^^

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

Nov 27 '06 #3
sh*******@yahoo.com wrote:
Gianni Mariani wrote:
>sh*******@yahoo.com wrote:
...
>>RatingComponent.cpp
===================

static RatingComponent * RatingComponent::_instance = 0;
^^^^^^^^^

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.
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.
Nov 27 '06 #4
sh*******@yahoo.com wrote:
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.
Nov 27 '06 #5
Ron Natalie wrote:
sh*******@yahoo.com wrote:
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.
Thanks to everybody who replied to my post.

Cheers
Shan

Nov 28 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: | last post by:
what is meaning of this? (MS VC++ .NET) ---------------------- Linking... machine.obj : error LNK2001: unresolved external symbol "private: static class std::vector<struct...
10
by: Dave | last post by:
const static int ARRAY_SIZE = 4; Comeau online gives this warning: "ComeauTest.c", line 10: warning: storage class is not first const static int ARRAY_SIZE = 4; Why is static const...
9
by: AnandRaj | last post by:
Hi guys, I have a few doubts in C. 1. Why static declartions are not allowed inside structs? eg struct a { static int i; }; Throws an error ..
4
by: nospam_timur | last post by:
Let's say I have two files, myfile.h and myfile.c: myfile.h: int myfunction(int x); myfile.c: #include "myfile.h"
14
by: Jess | last post by:
Hello, I learned that there are five kinds of static objects, namely 1. global objects 2. object defined in namespace scope 3. object declared static instead classes 4. objects declared...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.