473,406 Members | 2,259 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

"Uninstantiated" Class Member Functions?

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..."
%%%% <ya***@ieee.org> % Getting To The Point', *Balance of Power*, ELO
http://home.earthlink.net/~yatescr
Jul 22 '05 #1
3 2066
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
Jul 22 '05 #2
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.
Jul 22 '05 #3
Jacques Labuschagne <ja*****@clawshrimp.com> 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."
%%%% <ya***@ieee.org> % "Rockaria", *A New World Record*, ELO
http://home.earthlink.net/~yatescr
Jul 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: qazmlp | last post by:
Does static member function of a class have 'extern "C" linkage ? And what about non-static member functions ?
7
by: Srini | last post by:
Hello, Rules for inline functions say that they have to be defined in the same compilation unit as their declarations. For class member functions this means that the inline member functions must...
3
by: lovecreatesbeauty | last post by:
Predefined class member functions and inheritance How many member functions on earth can be provided (predefined) by standard-compliant compilers? Scott Meyers says that there are 6:...
3
by: Nagesh | last post by:
hi, I have seen the winvnc(tightvnc server) source code in this I seen that class member funtions are calling without instantiating the object i.e. like vncService::ShowDefaultProperties() where...
3
by: cweisbrod | last post by:
Hi All, I realize I may be posting to the wrong group, but I can't help but think my problem is more related to C++ than Microsoft's particular C++ compiler. I've been migrating a large...
12
by: Andy Terrel | last post by:
Okay does anyone know how to decorate class member functions? The following code gives me an error: Traceback (most recent call last): File "decorators2.py", line 33, in <module> s.update()...
1
by: Wynner | last post by:
I'm an old Delphi programmer getting into the C++ world, and trying to wrap my head around this problem. I have multiple classes derived from a generic class that passes one of it's functions as a...
6
by: jthep | last post by:
Hi I'm trying to write a JNI for a linkedlist class I wrote in C++. Basically I have a header file with the class definition and a C++ file with the definition of the class member functions. I...
5
emaghero
by: emaghero | last post by:
I have the following class declaration class class_name{ public: class_name(); // Constructor // Member functions void function_1(); void function_2(double *mat); void...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.