Static set member.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



All,

I am attempting to create a singleton class something like this:

class ThingManager
{

    static void show( Thing * thng );
    static void hide( Thing * thng );
    static void hideAll( void );

private:

    static std::set<Thing *,ThingComp> thingSet;
};

I get these errors:
[ed@localhost ~]$ g++ thing.cpp
thing.cpp: In static member function `static void ThingManager::show(Thing*)':
thing.cpp:7: error: `thingList' was not declared in this scope
thing.cpp: In static member function `static void ThingManager::hide(Thing*)':
thing.cpp:13: error: `thingList' was not declared in this scope
thing.cpp: In static member function `static void ThingManager::hideAll()':
thing.cpp:19: error: `thingList' was not declared in this scope

More details (still simple) in the attached files.

What am I doing wrong???

Adding a constructor or initializer to the cpp file is an error:
std::set<Thing *,ThingComp> ThingManager::thingSet();

Ed

#include "thing.h"


void ThingManager::show( Thing * thng )
{
    thingList.insert( thng );
}


void ThingManager::hide( Thing * thng )
{
    thingList.erase( thng );
}


void ThingManager::hideAll( void )
{
    thingList.erase( thingList.begin(), thingList.end() );
}

#include <set>

class Thing
{

public:

    Thing( void ) : iThing(42) {}
    int get( void ) const { return iThing; }

private:

    int iThing;
};


struct ThingComp
{
    bool operator()( Thing * thing1, Thing * thing2 )
    {
        return (thing1->get() < thing2->get());
    }
};


class ThingManager
{

    static void show( Thing * thing );
    static void hide( Thing * thing );
    static void hideAll( void );

private:

    static std::set<Thing *,ThingComp> thingSet;
};


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux