Static set member.

Smith-Rowland, Edward M ESmith-rowland@alionscience.com
Tue Aug 29 23:03:00 GMT 2006


What a maroon!

Thanks for the reply.

I actually had a *different* problem that this example was supposed to show.
I have attached the new sources (with the obvious problem fixed :-P).

The sources compile but the linking fails!
[ed@localhost ~]$ g++ thing.cpp
/tmp/ccAhcYMW.o(.text+0x11): In function `ThingManager::show(Thing*)':
: undefined reference to `ThingManager::thingSet'
/tmp/ccAhcYMW.o(.text+0x35): In function `ThingManager::hide(Thing*)':
: undefined reference to `ThingManager::thingSet'
/tmp/ccAhcYMW.o(.text+0x49): In function `ThingManager::hideAll()':
: undefined reference to `ThingManager::thingSet'
/tmp/ccAhcYMW.o(.text+0x57): In function `ThingManager::hideAll()':
: undefined reference to `ThingManager::thingSet'
/tmp/ccAhcYMW.o(.text+0x6d): In function `ThingManager::hideAll()':
: undefined reference to `ThingManager::thingSet'
collect2: ld returned 1 exit status

Somehow, All the classes are correct but the static object is not getting instantiated.


BTW: I realize the static thing in NOT thread safe.


-----Original Message-----
From: Young, Michael [mailto:Michael.Young@paetec.com]
Sent: Tue 8/29/2006 5:37 PM
To: Smith-Rowland, Edward M; gcc-help@gcc.gnu.org
Subject: RE: Static set member.
 
In ThingManager, you have a thingSet member, not a thingList.  Your function definitions reference a "thingList", which is not defined.

-----Original Message-----
From: gcc-help-owner@gcc.gnu.org [mailto:gcc-help-owner@gcc.gnu.org]On
Behalf Of Smith-Rowland, Edward M
Sent: Tuesday, August 29, 2006 5:17 PM
To: gcc-help@gcc.gnu.org
Subject: Static set member.


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




-------------- next part --------------
A non-text attachment was scrubbed...
Name: thing.h
Type: text/x-chdr
Size: 496 bytes
Desc: thing.h
URL: <https://gcc.gnu.org/pipermail/gcc-help/attachments/20060829/9ca13beb/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: thing.cpp
Type: text/x-c++src
Size: 356 bytes
Desc: thing.cpp
URL: <https://gcc.gnu.org/pipermail/gcc-help/attachments/20060829/9ca13beb/attachment-0001.bin>


More information about the Gcc-help mailing list