Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Will this constructor work ?

 
Men Gumani
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Thanks.
 
Ruben Soto
Ranch Hand
Posts: 1032
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there anything that makes you think it might not work?
 
Men Gumani
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The reason I raise this question is that I am reading chap 7 and I see a constructor like this :

I don't know if the one I asked will work or not, if you can explain at which stage the compiler knows type X is there and we can declare it, it would be great, even better if you can tell me the usage of such constructor.
Thanks again.
 
Ruben Soto
Ranch Hand
Posts: 1032
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The usage of such a constructor is to be used in mock exams to confuse people. That's basically it. In the real world you shouldn't use obscure features of the language, but make your code easy to read and maintain.

The constructor you showed is equivalent to this one:

 
Men Gumani
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh? Sorry buddy, but you sure it is

not

 
Ruben Soto
Ranch Hand
Posts: 1032
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Men Gumani wrote:Oh? Sorry buddy, but you sure it is

not


Men,

I think it's the way I explained. This test seems to support that:

 
Men Gumani
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Ruben
 
Ruben Soto
Ranch Hand
Posts: 1032
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No problem.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic