🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #3917

Is it legal to use 'this' in the initializer list of a constructor

#3917
From: Brett Bergquist
Date: Thu, 04 Apr 1996 18:15
30 lines
1489 bytes
consider the following classes:

	class bar;
	class foo
	{
	  public:
		foo(bar* b) : m_b(b) {}
	  private:
		bar* m_b;
	};

	class bar
	{
               public:
		bar() : m_f(this) {}
//			   ^^^ is this legal
	  private:
		const foo m_f;
	};

Is the use of 'this' legal to initialize the constant foo member.  If
not, how does one get a pointer to object being constructed within
the constructor initializer?
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu 
]
Technical Details
Message-ID: <3163b5ba.61651300@gateway>
Path: arc1-ca.pugleaf.net!fido.asd.sgi.com!austern

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!fido.asd.sgi.com!austern
From: brettb@acti-ct.com (Brett Bergquist)
Newsgroups: comp.std.c++
Subject: Is it legal to use 'this' in the initializer list of a constructor
Date: 04 Apr 1996 10:15:41 PST
Organization: PCNet -- Connecticut's Internet Service Provider.
Approved: austern@isolde.mti.sgi.com
Message-ID: <3163b5ba.61651300@gateway>
NNTP-Posting-Host: isolde.mti.sgi.com
X-Original-Date: Thu, 04 Apr 1996 11:48:43 GMT
X-Newsreader: Forte Agent .99d/32.182
X-Auth: PGPMoose V1.1 PGP comp.std.c++
 iQBVAwUBMWQRzUy4NqrwXLNJAQGGhgH9GoLdc+G3dsy6+3mfyv0edabr39/K6IYr
 KfJ42xxgT6179LcnV8WJOOcGmZ2LWq+VwrJVLdG+VYdgm/mGGvmUYw==
 =C5au
Originator: austern@isolde.mti.sgi.com