Why does this class object declaration work?

  • A+
Category:Languages

Suppose I have a class

class Test{   public:     int x;     Test(const Test& obj){x=obj.x;} }; 

Why does

Test object_name(Test random_name); 

run and does not need another object as a parameter?. .Something like Test random_name(Test another_random(...)), making it a never ending way of declaring the object?

 


This line:

Test object_name(Test random_name); 

declares a function called object_name that takes a Test as a paramter and returns a Test. It does not declare an object. It is perfectly legal to declare a function like this inside another function, it's just implicitly extern.

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: