'this'

'this'

Post by m.. » Fri, 31 Mar 2000 04:00:00



Hi,

Is it possible to derefernce the 'this' pointer with a constructor?

The code I have is :-

Class::Class(...) : BaseClass(*this)
{
    ...

TIA

Mark Williams
http://www.techop.co.uk

 
 
 

'this'

Post by TiTi » Fri, 31 Mar 2000 04:00:00



Quote:> Is it possible to derefernce the 'this' pointer with a constructor?

Yes, but only in one circumstance: to pass a reference.

Quote:> The code I have is :-
> Class::Class(...) : BaseClass(*this)
> {
>     ...

Yes, if the constructor of BaseClass reads:

    BaseClass(const Class&)
or
    BaseClass(Class&)

Why would you need a reference to a superclass in your class?

TiTi
--
comp.lang.c++:
   * Read Shiva's "Welcome to comp.lang.c++" before posting to this
newsgroup:
   http://www.slack.net/~shiva/welcome.txt
   * FAQ (frequently asked questions) :
http://www.cerfnet.com/~mpcline/c++-faq-lite/
#exclude <windows.h>

 
 
 

'this'

Post by Ron Natali » Fri, 31 Mar 2000 04:00:00



> X-No-Archive: Yes

> > Is it possible to derefernce the 'this' pointer with a constructor?
> > The code I have is :-

> > Class::Class(...) : BaseClass(*this)
> > {
> Why do you need this? You BaseClass already has access to the very same "this".

Of course and you can most likely static/dynamic cast back to it  unless you're
hierarchy is too wierd.

The time where I do use this construct however is not to inialize base classes,
but to initialize members with their containing class.

 
 
 

'this'

Post by Lornis Van Lo » Sat, 01 Apr 2000 04:00:00





>> X-No-Archive: Yes

>> > Is it possible to derefernce the 'this' pointer with a constructor?
>> > The code I have is :-

>> > Class::Class(...) : BaseClass(*this)
>> > {
>> Why do you need this? You BaseClass already has access to the very same "this".

>Of course and you can most likely static/dynamic cast back to it  unless you're
>hierarchy is too wierd.

>The time where I do use this construct however is not to inialize base classes,
>but to initialize members with their containing class.

yes, but I can also imagine a case where the base class may be
initialized with either this or some other object, i.e:

Class::Class() : BaseClass(*this) {}
Class::Class( Base & _rBase ) : BaseClass( _rBase ) {}

which would make the reply of "this is incredulous", sound rather
incredulous.

 
 
 

1. Q:'default' before 'case' in 'switch'

Hi, all
Does anybody know whether this code

switch (x)
   {
   default: return 0;
   case 1 : return 1;
   case 2 :
   etc..
   }
is complient with the Standard?

It compiles (and executes OK) with MSVC++6.0
I haven't check other ones, but it looks a bit bothering to me

Thanx

--
rado
http:://members.tripod.com/~radosoft

Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]

[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]

2. Back Up My Files Question

3. File format for '.dll's' and '.lib'

4. Please Help! Optimum16 + Creative CD = No CD-Audio

5. 'initializing' : truncation from 'const double' to 'float' warning

6. IBM concede Win 95 is

7. {'a','b','\0'} not equivalent to "ab"??

8. Windows 2000 Server +Windows XP

9. TreeView: what's the difference btw 'child' and 'sibling'?

10. why I can not use getprocAddress(loadModule('gdi32'),'textouta')?

11. ADSI COM 'put_' & 'get_' methods

12. How to get window with 'close' and 'maximize' boxes

13. Is there any ways to distinguish 'restart' and 'shutdown'?