473,396 Members | 2,018 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,396 software developers and data experts.

Please explain this to me !!


HI All ,:)

I am a VC++ programmer,and some time My <b>Acumen</b> ask Microsofts
VC++ (Visual Studio VC++ 6.0 )complier to complile my <b>senseless
programs </b> ! :)

<i><b>

See what I have asked this time to compile !!..</b></i>

This is console based program, in which i am trying to call Member
function of My class With a NULL pointer .

And it is working fine....:cool:

Please some one explain this to me ....is this happening of coz Compiler
is fed up with my programs !! :-D

#include "stdafx.h"

#include <iostream.h>

class A

{

public :

int var;

A()

{

cout<<"In Consrtuctor !!";

}

~A()

{

cout<<"\nClass destroyed !!\n";

}

void EvenNullPointerCanCallme(int a);

};

void A::EvenNullPointerCanCallme(int a)

{

int *aa=new int[100];

cout<<"\nHow is that possible !!\n";

delete []aa;

}

int main(int argc, char* argv[])

{

A *nullPtr=NULL;//see i made it NULL

nullPtr->EvenNullPointerCanCallme(2);//How daring i am :)

delete nullPtr;//I cannot call destructor !

return 0;

}

Are member functions statically linked with the Object name !!

Actually i never found any concept of accessing Class member function
with NULL pointers in Any of C++ books Which I have read (Plz let me
know if u people have found it in any book !).

I am grateful to all u peoples who had a look at my program !!

Now see i am getting famous or what :)
--
Abhishek Srivastava
Software engg
India , Noida
:)
Posted via http://dbforums.com
Jul 19 '05 #1
2 1930
Abhish wrote:


Actually i never found any concept of accessing Class member function
with NULL pointers in Any of C++ books Which I have read (Plz let me
know if u people have found it in any book !).


The only reason this works is because you aren't accessing
any data in the methods you call. Access the vaiable 'var'
and the program will crash.
Jul 19 '05 #2
On Sat, 01 Nov 2003 04:58:55 -0500, Abhish wrote:
This is console based program, in which i am trying to call Member
function of My class With a NULL pointer .

And it is working fine....:cool:

Please some one explain this to me ....is this happening of coz Compiler
is fed up with my programs !! :-D


Technically, calling a member function on a null pointer is undefined
behaviour, so anything might happen. That it works in this case is down to
the way your compiler implements non-virtual member functions: probably
just like a free function with an extra parameter for "this". Your member
function doesn't use any members of the class, hence the "this" pointer
isn't dereferenced and nothing bad happens. Try modifying the function so
that it uses a member variable and see what happens then.
Jul 19 '05 #3

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

Similar topics

9
by: DD | last post by:
Hello, Could anyone please help me?? Is there somebody who could explain me how to make a connection to a access database with a python cgi script. I would like to use common sql commands in my...
3
by: VijayShankar | last post by:
Can u be more specific on your question Anyway its not like Session variables are available for sometime and not available for sometime. When your session starts it is very much available...
1
by: Yash | last post by:
Hi, Can someone please explain to me what the StreamReader.DiscardBufferedData method does? The documentation says "Use DiscardBufferedData to seek to a known location in the underlying stream...
5
by: KathyB | last post by:
If someone could just explain this to me...I just don't get it! I have an aspx page where I retrieve several session variables and use xmlDocument to transform xml file with xsl file into an...
12
by: Sanjeev | last post by:
Output of followin program at Turbo C++ 3.0 is 7 ( Not 2 or 3). Please explain why ? //////////////////////////////////////////////// #include<stdio.h> #include<string.h> void main() {
2
by: garyusenet | last post by:
I could do with something similiar, can you tell me if you think this would work for me, and if there's any advantage in working with controls this way than how I currently am. At the moment...
9
by: colin.mcnulty | last post by:
Hi, I'm a SQL Server DBA, but I guess that won't buy me any friends round here huh? ;-) I've been asked to look at the SQL that's being executed on a DB2 database from a web app, specifically...
61
by: warint | last post by:
My lecturer gave us an assignment. He has a very "mature" way of teaching in that he doesn't care whether people show up, whether they do the assignments, or whether they copy other people's work....
3
by: sathishc58 | last post by:
Hi All, Here is the code which generates Segmentation Fault. Can anyone explain why the third printf fails and the first printf works? main() { char ch={"Hello"}; char *p; ...
2
by: sathishc58 | last post by:
Hi All Please explain why strlen returns() "16" as output here and explain the o/p for sizeof() as well main() { char a={'a','b','c'}; printf("strlen=%d\n", strlen(a));...
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
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
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...
0
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...
0
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,...

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.