develooper Front page | perl.perl6.language | Postings from April 2002

Re: Defaulting params

Thread Previous | Thread Next
From:
Luke Palmer
Date:
April 11, 2002 09:44
Subject:
Re: Defaulting params
Message ID:
Pine.LNX.4.33.0204111034270.18737-100000@babylonia.flatirons.org
> 	class myobj {
> 		...
> 		int a,b,c;
> 		myobj(int aa, int bb, int cc) :
> 			a(aa), b(bb), c(cc) const {}
> 		...
> 	};

Ummm no. Straight from Bjarne: "You can't have a const constructor." You 
just do what you did without the const. A const myobj is essentially 
equivalent (with the exception of not being allowed to call methods not 
marked 'const', except the constructor) to:

	class myobj {
		const ...
		const int a,b,c;
`		myobj(int aa, int bb, int cc) :
			a(aa),b(bb),c(cc) { }
	};

So you're initializing the const variables just like you would instance 
consts. The constructor can't alter them, but the initializer (thing 
before the constructor) can.

But, this isn't a C++ list, so on to Perl. I should certainly hope you can 
have instance constants. They can be quite useful, though optimization 
doesn't work as well for them.

Oh, and just so you know, I'm basically a C++ linguist. I have practically 
memorized Bjarne's The C++ Programming Language. And by that, I maintain 
that C++ is the _best_ compiled language. Or at least in my opinion.

Luke


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About