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

Pointer to a Partially-Constructed Object

Hello all,

Please consider the following code:

class Bar;

class Foo {
Bar *m_pBar;
public:
Foo(Bar *pBar): m_pBar(pBar) {}
};

class Bar {
Foo m_Foo;
public:
Bar(): m_Foo(this) {}
};

It would certainly be wrong for Foo::Foo() to dereference pBar since
the Bar object is still being constructed and therefore does not
exist. However, is it wrong to even cache off the pointer for later
use as shown?

Thanks,
Dave

May 28 '07 #1
1 1228
be***********@yahoo.com wrote:
Hello all,

Please consider the following code:

class Bar;

class Foo {
Bar *m_pBar;
public:
Foo(Bar *pBar): m_pBar(pBar) {}
};

class Bar {
Foo m_Foo;
public:
Bar(): m_Foo(this) {}
};

It would certainly be wrong for Foo::Foo() to dereference pBar since
the Bar object is still being constructed and therefore does not
exist. However, is it wrong to even cache off the pointer for later
use as shown?
No. If you only store the pointer value, that's fine.

May 28 '07 #2

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

Similar topics

1
by: geradeaus | last post by:
Even if you upload an image partially with ftp software, you can still read the image. Only the image will be partially gray. So, can I determine with a php-function if an image is fully uploaded...
79
by: syntax | last post by:
what is the size of a pointer? suppose i am writing, datatype *ptr; sizeof(ptr); now what does this sizeof(ptr) will give? will it give the size of the
11
by: Chris Croughton | last post by:
I have a requirement to partially preprocess C code. By 'partially' I mean that I need to define some macros (to the utility) and have it preprocess only those macros, leaving everything else...
3
by: Wolfgang | last post by:
Is it possible in C# .NET to create a window that is always on top of all other windows, while at the same time being partially transparent? If not in C# .NET, how about in C++ .NET? As an...
7
by: Ioannis Vranos | last post by:
I have been checking C++/CLI lately by using VC++ 2005 Express Beta 1 (should be called Alpha though). In managed extensions we could pass managed pointers to functions taking unmanaged pointers...
1
by: Pierre | last post by:
Hi all, I have developped a set of WSs and everything works fine when I try it on my local network. When I export them on my host's server though I get the following error on my client: ...
9
by: tkpmep | last post by:
I have a list y >>>y from which I want to extract only the 2nd and 4th item by partially unpacking the list. So I tried >>>a,b = y Traceback (most recent call last): File "<interactive...
3
by: mark.bergman | last post by:
Running lint on code initialising a local 2-D array gives a warning. void f(void) { int a = { 0 }; ... lint gives "warning: Partially elided initialisation..." Should this be happening,...
8
by: Rahul | last post by:
Hi, Is there a way to partially specialize only a member function of a template class (not the whole class). e.g. template <typename A, typename B> class Base { public:
3
by: .rhavin grobert | last post by:
guess you have the following: _________________________________________________ template <class T> class CQVector { public: // find an element, returns index or -1 if none is found int...
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
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
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.