473,387 Members | 1,687 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,387 software developers and data experts.

Static memfun through null ptr

Hello all,

is it legal to call a static member function with a null pointer?

Is this correct C++?

class X {
public:
static void f() {}
};

int main() {
X* pX = 0;
pX->f();
}

Thanks Oliver
Jul 19 '05 #1
3 2489
Oliver Anhuth wrote:
Hello all,

is it legal to call a static member function with a null pointer?

Is this correct C++?

class X {
public:
static void f() {}
};

int main() {
X* pX = 0;
pX->f();
}

Thanks Oliver


No, it is not legal.

The behaviour is undefined.

Jul 19 '05 #2

"Oliver Anhuth" <q4******@bonsai.fernuni-hagen.de> wrote in message news:bj**********@beech.fernuni-hagen.de...
Hello all,

is it legal to call a static member function with a null pointer?

No. It is illegal to dereference, that is apply * or -> to a null pointer
even if the result would appear not to care about the actual value of
the pointer.
Jul 19 '05 #3

"Oliver Anhuth" <q4******@bonsai.fernuni-hagen.de> wrote in message
news:bj**********@beech.fernuni-hagen.de...
Hello all,

is it legal to call a static member function with a null pointer?

Is this correct C++?

class X {
public:
static void f() {}
};

int main() {
X* pX = 0;
pX->f();
}

Thanks Oliver


No, it's not legal, but if it's static then you don't need an instance
variable at all. Just call it like this:

X::f();

-Howard


Jul 19 '05 #4

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

Similar topics

5
by: Chris | last post by:
Hi I have a scenario where I've created another AppDomain to dynamically load a DLL(s) into. In this newly loaded DLL I want to call a static method on a class. The problem arise is that I have...
3
by: Ryan Steckler | last post by:
I found this behavior while trying to implement a singleton class. Below is a somewhat more straight forward example, though admittedly less useful in real life. The basic problem is that when a...
15
by: Sharon | last post by:
I’m trying to build a generic Publisher-Subscriber that will work over the net, so I’m using the Remoting. I wish that the subscriber user will be notify about the messages sent by the...
1
by: Greif | last post by:
I am trying to call a static method within a sealed class. However, the wrong method keeps getting called instead. In a seperate class I am calling the following code: LogHelper.Log("Sample...
9
by: Joanna Carter \(TeamB\) | last post by:
Following on from the other discussion, I have to just check something out with reference to disposal of resources held in static fields. I have a Persistence Framework that is 'globally...
12
by: fox | last post by:
How do I (portably) make a forward reference to a static (I mean file-scope) variable? I've been using "extern" for years, for example: extern int x; int foo(void) { return x++; }
3
by: dmoore | last post by:
Hi Folks: I have a question about the use of static members in Python/C extensions. Take the simple example from the "Extending and Embedding the Python Interpreter" docs: A simple module...
17
by: copx | last post by:
I don't know what to think of the following.. (from the dietlibc FAQ) Q: I see lots of uninitialized variables, like "static int foo;". What gives? A: "static" global variables are initialized...
8
by: aarklon | last post by:
Hi all, see:- http://linuxgazette.net/issue51/pramode.html
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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,...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.