P
pedagani
Hello Comp.lang.c++ members,
Consider the " begin " routine for a class with an interator.
Iterator begin() {
return( Iterator( _class_element ) );
}
where the constructor for the iterator is defined as
Iterator::Iterator( Node* example) :_iter_element ( example ) {};
what confuses me is the way the constructor is used ( Iterator(
_class_element ) ).
Correct me if I'm wrong, does a constructor implicitly return an
object?
I had never seen a constructor used in this fashion in regular
textbooks. I had understood the constructor as something that is
invoked at the *declaration* of a variable (eg. classname eg (arg) ).
eg is the class object and the chunck of memory that is created by the
constructor is assigned to variable "eg".
However, in the iterator case, how is the memory created in the process
of invoking the constructor? If I understand correctly, a chuck of
memory is created on the fly with no variable tag assigned which is in
contrary to the basic idea of a programming language?
Thanks.
Consider the " begin " routine for a class with an interator.
Iterator begin() {
return( Iterator( _class_element ) );
}
where the constructor for the iterator is defined as
Iterator::Iterator( Node* example) :_iter_element ( example ) {};
what confuses me is the way the constructor is used ( Iterator(
_class_element ) ).
Correct me if I'm wrong, does a constructor implicitly return an
object?
I had never seen a constructor used in this fashion in regular
textbooks. I had understood the constructor as something that is
invoked at the *declaration* of a variable (eg. classname eg (arg) ).
eg is the class object and the chunck of memory that is created by the
constructor is assigned to variable "eg".
However, in the iterator case, how is the memory created in the process
of invoking the constructor? If I understand correctly, a chuck of
memory is created on the fly with no variable tag assigned which is in
contrary to the basic idea of a programming language?
Thanks.