static storage class error.

Discussion in 'C++' started by shan_rish@yahoo.com, Nov 27, 2006.

  1. Guest

    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, 2006
    #1
    1. Advertising

  2. wrote:
    ....
    > RatingComponent.cpp
    > ===================
    >
    > static RatingComponent * RatingComponent::_instance = 0;

    ^^^^^^^^^

    loose the "static" here.

    >
     
    Gianni Mariani, Nov 27, 2006
    #2
    1. Advertising

  3. Guest

    Gianni Mariani wrote:
    > 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, 2006
    #3
  4. wrote:
    > Gianni Mariani wrote:
    >> 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.
     
    Gianni Mariani, Nov 27, 2006
    #4
  5. Ron Natalie Guest

    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.
     
    Ron Natalie, Nov 27, 2006
    #5
  6. Guest

    Ron Natalie wrote:
    > 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, 2006
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Patrick Hoffmann
    Replies:
    3
    Views:
    2,841
    Christian Jan├čen
    Aug 8, 2003
  2. sarathy
    Replies:
    2
    Views:
    668
    sarathy
    Jul 17, 2006
  3. jacob navia

    Re: storage class static of functions

    jacob navia, Jan 15, 2008, in forum: C Programming
    Replies:
    2
    Views:
    279
    Chris Dollin
    Jan 15, 2008
  4. Willem

    Re: storage class static of functions

    Willem, Jan 15, 2008, in forum: C Programming
    Replies:
    2
    Views:
    285
    Chris Dollin
    Jan 15, 2008
  5. asit

    storage class static of functions

    asit, Jan 15, 2008, in forum: C Programming
    Replies:
    2
    Views:
    328
    Ravishankar S
    Jan 16, 2008
Loading...

Share This Page