"Uninstantiated" Class Member Functions?

R

Randy Yates

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..."
%%%% <[email protected]> % Getting To The Point', *Balance of Power*, ELO
http://home.earthlink.net/~yatescr
 
R

red floyd

Randy said:
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
 
J

Jacques Labuschagne

Randy said:
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.
 
R

Randy Yates

Jacques Labuschagne said:
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."
%%%% <[email protected]> % "Rockaria", *A New World Record*, ELO
http://home.earthlink.net/~yatescr
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top