Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > overloading operators (basic)

Reply
Thread Tools

overloading operators (basic)

 
 
Ben Pope
Guest
Posts: n/a
 
      12-09-2005
Jacek Dziedzic wrote:
> Ben Pope wrote:
>> It's perfectly acceptable.
>>
>> Just don't try to do it with constructors, it won't achieve what you
>> want.

>
> but variant A is fine, right?
>
> // --- variant A
> Foo::Foo(int a) {};
> Foo::Foo() : Foo(3) {};
> // --- variant B
> Foo::Foo(int a) {};
> Foo::Foo() {Foo(3);}
>
> is fine, right?


I don't see how it would be, are you referring to:

class Foo {
public:
Foo(int a) : a_(a) {}
Foo() : Foo(3) {}
private:
int a_;
};

int main() {
Foo foo;
}

Foo is not a base or member of itself, so I'm not sure what you are
intending to initialise.

Ben Pope
--
I'm not just a number. To many, I'm known as a string...
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Overloading new and delete operators Nimmi Srivastav C++ 3 02-02-2004 07:20 AM
Troube overloading operators Zenon C++ 6 10-24-2003 11:52 PM
overloading operators B.R.Kumar C++ 2 10-10-2003 09:41 PM
Re: Overloading New/Delete Operators C Wood C++ 4 07-10-2003 10:24 AM
Re: Overloading New/Delete Operators Ron Natalie C++ 0 07-09-2003 05:16 PM



Advertisments