So putting static on a member in a class declaration is only a declaration -- 
you still need a definition.  This is done outside of the class declaration 
itself (much like how most methods at declared in the class declaration but 
defined elsewhere).  So generally this means that if you add "static 
Fetcher_map active_fetchers;" to the class declaration for the class MyClass in 
MyClass.hh, you then add something like the following in your MyClass.cc:

Fetcher_map MyClass::active_fetchers;

Hope that helps.

-- Murphy

On Feb 18, 2011, at 8:12 PM, Ricardo Bennesby wrote:

> Hi. I declared the attribute with static modifier in header file as follows:
>    private:
>            static Fetcher_map active_fetchers;
> But it doesn't compile when I put the static modifier. 
> This accessed in .cc file in different methods and initialized. But when it 
> is accessed in methods called by event handlers, as flow_stats_in, it seems 
> that another instance of active_fetcher is created, because it size is zero.
> So I would like to know if I am using the correct modifier or if I can have 
> the same instance of class some other manner, without using modifiers.
> Thank you so much.  
> 
> 2011/2/18 Murphy McCauley <[email protected]>
> You say you tried to use the static modifier but it didn't work.  Could you 
> explain a bit more what you mean by "didn't work"?  Didn't compile?  Didn't 
> have the expected results?  Also, a short code snippet might be helpful.
> 
> -- Murphy
> 
> On Feb 17, 2011, at 4:37 PM, Ricardo Bennesby wrote:
> 
>> Hi all,
>> 
>> I am developing a component using C++ and I am having the following problem:
>> In header file, in the definition of a class, I declared an attribute and I 
>> want that this attribute belongs to the class and not to a instance of this 
>> class.
>> I tried to use static modifier but it didn't work.
>> It seems to me that handlers of events create different instances of the 
>> class. For example,  the method handle_flow_stats_in inserts elements in a 
>> object of the type Fetcher_map but the handle_datapath_join indicates that 
>> the size of object is still zero.
>> 
>> Sorry if I didn't make myself clear.
>> 
>> Any suggestions?
>> 
>> -- 
>> Ricardo Bennesby da Silva
>> Ciência da Computação - UFAM
>> LabCIA - Laboratório de Computação Inteligente e Autonômica 
>> 
>> _______________________________________________
>> nox-dev mailing list
>> [email protected]
>> http://noxrepo.org/mailman/listinfo/nox-dev_noxrepo.org
> 
> 
> 
> 
> -- 
> Ricardo Bennesby da Silva
> Ciência da Computação - UFAM
> LabCIA - Laboratório de Computação Inteligente e Autonômica 
> 


_______________________________________________
nox-dev mailing list
[email protected]
http://noxrepo.org/mailman/listinfo/nox-dev_noxrepo.org

Reply via email to