473,783 Members | 2,564 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

"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::CheckI fMYCLASS(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 2090
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_instance s_ = 0;

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

Jacques.
Jul 22 '05 #3
Jacques Labuschagne <ja*****@clawsh rimp.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_instance s_ = 0;

int main(){
cout << "Instantiat ed: " << 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
1607
by: qazmlp | last post by:
Does static member function of a class have 'extern "C" linkage ? And what about non-static member functions ?
7
2862
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 be defined either within the class or within the same header file. But its generally a good programming practice to have the declarations and definitions in seperate files. This would make the future maintenance of the code easier.
3
509
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: (1)default constructor, (2)copy constructor, (3)destructor, (4)assignment operator, (5)address-of operator (non-const), (6)address-of operator (const), in `Effective
3
4945
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 vncService is a class name not an refrence or instantiated object. is the above notation is possible or not?if yes how should i declare that class(vncService) so that i can call without instantiating the object. If any of u know pls answer to...
3
1628
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 project from CodeWarrior to Visual Studio and I'm having some difficulty with the Microsoft compiler. Here's the basic problem with simplified code:
12
4098
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() File "decorators2.py", line 13, in __call__ retval = self.fn.__call__(*args,**kws) TypeError: update() takes exactly 1 argument (0 given)
1
1586
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 parameter to another function. The code is very complex, so I've written this abridged version of what I am trying to do. // genClass.h #ifndef genClassH #define genClassH #include <Classes.hpp>
6
11896
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 have a record file llist.h class llist { private: record *start; char filename; int readfile();
5
1892
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 function_3();
0
9643
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10147
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10083
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9946
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8968
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4044
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.