• Post Reply Bookmark Topic Watch Topic
  • New Topic

Calling one constructor from another  RSS feed

 
merlin bar
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Why does the call to Test() int the second ctor cause the compiler to complain? (cannot resolve symbol).
 
chi Lin
Ranch Hand
Posts: 348
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
When call one constructor from another, you use this() or
this(necessary parameter), and it should be the first statement
inside the constructor.
 
merlin bar
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thats great, thanks!
 
Gabriel White
Ranch Hand
Posts: 233
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now why doesn't this work?? It looks properly formatted besides the other constructor call not being the first statement.

[ December 15, 2003: Message edited by: Steve Wysocki ]
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"this" is a keyword. Use is like so:

Note that a call to this(), if it appears, must be the first line in a constructor -- i.e., you can't print something first, then call this().
[/code]
 
Gabriel White
Ranch Hand
Posts: 233
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks E, total brain fart on that one. I just didn't key in on the command that I have used before: this();. Sorry to waste your valuable brain cells on that one.
Thanks
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!