Re: Two questions - thanks!

From: Scuro (crsoft_at_questolevalo.libero.it)
Date: 11/24/04


Date: Wed, 24 Nov 2004 00:39:06 +0100

Chutian wrote:

> What's the best way to share data between classes?

To share data between objects of the same class i suggest to use a
static data, to share data between two different classes, there are many
solutions. One quite elegant solution, if it makes sense, is to inherit
from a common superclass that shares the data.

> What's the purpose of define a member function in a class as 'static'? Just
> for it to access static member variables? Is there any other reasons?

 From "thinking in C++":
"static member functions

You can also create static member functions that, like static data
members, work for the class as a whole rather than for a particular
object of a class. Instead of making a global function that lives in
and “pollutes” the global or local namespace, you bring the
function inside the class. When you create a static member
function, you are expressing an association with a particular class."



Relevant Pages

  • Re: Static/ non-static member access
    ... Static member functions certainly can use non-static members, ... have no "this" pointer and thus don't operate implicitly on an object ... // Placement new - constructs a T in the memory pointed to by temp. ...
    (microsoft.public.vc.language)
  • Re: Calling static member function through object instance
    ... call was to a static member or a non-static member. ... Some paragraphs before discuss class member access in general and from ... following the general concept as close as possible. ... AFAIK static member functions were not present in C++ from the beginning ...
    (comp.lang.cpp)
  • Re: Exporting static member functions
    ... Have you linked with the import library created by the creation of the dll ... but only for the static member functions. ... static CCnlVar *GetAllCnlVar; ...
    (microsoft.public.vc.language)
  • Re: static member
    ... >> It's my understanding a static member variable will be one instance ... >> among all objects created from it, and static member functions only ... Every dog has a unique name, every dog has a unique age. ...
    (comp.lang.cpp)
  • Re: copy constructor clarification
    ... operator= cannot be a static member as you show below. ... The first parameter is implied. ... >> because of language interoperability problems but rather as what? ... They are similar to global function ISO C++ operator overloading. ...
    (microsoft.public.dotnet.languages.vc)