[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    Re: kconfigxt singleton problem?
From:       Ricardo Cruz <rpmcruz () clix ! pt>
Date:       2006-06-08 1:25:15
Message-ID: 200606080225.15127.rpmcruz () clix ! pt
[Download RAW message or body]


 I think Robert is confused because static is already used in different 
context for different meanings.

 A static function/variable outside a class means that the function/variable 
can only be used within that file.

 A static variable inside a function means that the variable will be created 
at  the first time the function is called, and will keep living for sequent 
calls.

 A static function/variable in a class means that it doesn't really belong to 
the class... Think about them as if instead of being inside of a class, they 
were global, just withing a namespace. Eg.

You may think of:
class QStringList
{ static void split(); }

as:
namespace QStringList
{ void split(); }

 You even access it like if it was the former. I.e: QStringList::split().

Cheers,
 Ricardo

Em Quinta, 8 de Junho de 2006 01:37, o Michael Pyne escreveu:
> On Wednesday 07 June 2006 15:02, Robert Hogan wrote:
> > interesting.  not sure i understand why the difference arises though in
> > the treatment of static vs non-static members for pointers. where can i
> > look for an explanation?
>
> Hopefully I can explain satisfactorily:
>
> A static class method does not require an object to operate on.  In other
> words, there is no implicit "this" pointer.  (Try it!)  This also means
> that you can't use non-static member variables.  But you don't need to
> construct an object to use the static method either.
>
> In essence it is a normal function namespaced into a class.  Indeed this is
> what it's often used for, like how Qt 3 how QStringList::split(), which was
> a static function so you could call it without needing a QStringList.
>
> On the other hand, a non-static member requires two things: A pointer to
> the function, and an object to use that pointer on.  That's because these
> kind of functions rely on the implicit this pointer that is missing from
> the static functions.
>
> Or in short: One type has "this", one does not.
>
> Regards,
>  - Michael Pyne

-- 
Real programmers don't bring brown-bag lunches.  If the vending machine
doesn't sell it, they don't eat it.  Vending machines don't sell
quiche.
 
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic