🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by Brett Bergquist Thu, 04 Apr 1996 18:15
Is it legal to use 'this' in the initializer list of a constructor
#3917
Author: 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 
]
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads