Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > "Uninstantiated" Class Member Functions?

Reply
Thread Tools

"Uninstantiated" Class Member Functions?

 
 
Randy Yates
Guest
Posts: n/a
 
      12-20-2004
Hi,

Is there a way to write a class member function that does not
require an instantiation of the object to be invoked? For
example,

class MYCLASS
{
bool CheckIfMYCLASS(string &teststring);
}

int main(int argc, char* argv[])
{
MYCLASS* pmc;

if MYCLASS::CheckIfMYCLASS(argv[1])
{
pmc = new MYCLASS;
}
}
--
% Randy Yates % "And all that I can do
%% Fuquay-Varina, NC % is say I'm sorry,
%%% 919-577-9882 % that's the way it goes..."
%%%% <(E-Mail Removed)> % Getting To The Point', *Balance of Power*, ELO
http://home.earthlink.net/~yatescr
 
Reply With Quote
 
 
 
 
red floyd
Guest
Posts: n/a
 
      12-20-2004
Randy Yates wrote:
> Hi,
>
> Is there a way to write a class member function that does not
> require an instantiation of the object to be invoked? For
> example,
>
>[redacted]


look up static member functions
 
Reply With Quote
 
 
 
 
Jacques Labuschagne
Guest
Posts: n/a
 
      12-20-2004
Randy Yates wrote:
> Hi,
>
> Is there a way to write a class member function that does not
> require an instantiation of the object to be invoked? For
> example,


As RF said, static functions fit the bill.

class M{
private:
static unsigned long num_instances_;
public:
M(){ ++num_instances; }
static bool instantiated(){ return num_instances_ > 0; }
};
unsigned long M::num_instances_ = 0;

int main(){
cout << "Instantiated: " << boolalpha << M::instantiated() << endl;
}

Jacques.
 
Reply With Quote
 
Randy Yates
Guest
Posts: n/a
 
      12-21-2004
Jacques Labuschagne <(E-Mail Removed)> writes:

> Randy Yates wrote:
>> Hi,
>> Is there a way to write a class member function that does not
>> require an instantiation of the object to be invoked? For
>> example,

>
> As RF said, static functions fit the bill.
>
> class M{
> private:
> static unsigned long num_instances_;
> public:
> M(){ ++num_instances; }
> static bool instantiated(){ return num_instances_ > 0; }
> };
> unsigned long M::num_instances_ = 0;
>
> int main(){
> cout << "Instantiated: " << boolalpha << M::instantiated() << endl;
> }
>
> Jacques.


Thanks, Jacques and RF.
--
% Randy Yates % "She's sweet on Wagner-I think she'd die for Beethoven.
%% Fuquay-Varina, NC % She love the way Puccini lays down a tune, and
%%% 919-577-9882 % Verdi's always creepin' from her room."
%%%% <(E-Mail Removed)> % "Rockaria", *A New World Record*, ELO
http://home.earthlink.net/~yatescr
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Nested Class, Member Class, Inner Class, Local Class, Anonymous Class E11 Java 1 10-12-2005 03:34 PM
parse error in gcc but success in vc.net, call a non_template class's template member function from a template class's member function! ken C++ 2 06-28-2005 06:57 AM
Can Derived class static member access protected member from base class? Siemel Naran C++ 4 01-12-2005 06:46 PM
Cannot refer to an instance member of a class from within a shared method or shared member initializer without an explicit instance of the class. DJ Dev ASP .Net 3 02-08-2004 04:19 PM
How would I use qsort to sort a struct with a char* member and a long member - I want to sort in order of the long member Angus Comber C Programming 7 02-05-2004 06:41 PM



Advertisments