Re: can I declare a class variable inside that class method?
From: Russell Hanneken (me_at_privacy.net)
Date: 06/15/04
- Next message: jeffc: "Re: can I declare a class variable inside that class method?"
- Previous message: John Black: "can I declare a class variable inside that class method?"
- In reply to: John Black: "can I declare a class variable inside that class method?"
- Next in thread: jeffc: "Re: can I declare a class variable inside that class method?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 15 Jun 2004 15:22:18 GMT
John Black wrote:
>
> Suppose I have a class,
>
> class MyClass{
> public:
> MyClass();
> MyClass(MyClass);
Suppose you wrote
MyClass x;
MyClass y(x);
Because the copy constructor parameter is passed by value, a copy of x
is made, and the copy is sent to the copy constructor. But to make the
copy, the MyClass copy constructor would have to be invoked. And then
the argument would have to be copied, using the MyClass copy constructor
again. And so on...
The point is, your copy constructor should take a reference, not a copy:
MyClass(MyClass const &);
> int func();
> };
>
> Then can I declare a MyClass object inside MyClass::func()?
>
> int MyClass::func(){
> MyClass obj;
> <......>
> }
Sure.
-- Russell Hanneken eunaarxra@cbobk.pbz Use ROT13 to decode my email address.
- Next message: jeffc: "Re: can I declare a class variable inside that class method?"
- Previous message: John Black: "can I declare a class variable inside that class method?"
- In reply to: John Black: "can I declare a class variable inside that class method?"
- Next in thread: jeffc: "Re: can I declare a class variable inside that class method?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|