overload "="

0

0infinity0

Why wont the operator work

#include <iostream.h>
class A
{
public:
A * operator = (A * rhs)
{
cout << "Ptr cpy" << endl;
return this;
}

private:
};

main()
{
A *a1;

A* a2 = new A();

a1 = a2;
}
 
A

Alf P. Steinbach

* (e-mail address removed):
Why wont the operator work

#include <iostream.h>

That's a non-standard header.

class A
{
public:
A * operator = (A * rhs)
{
cout << "Ptr cpy" << endl;
return this;
}

private:
};

main()

'main' must have result type 'int'.

{
A *a1;

A* a2 = new A();

a1 = a2;

You're assigning to the pointer a1. Your operator only comes into play
if you assign to an object of type A. The pointer a1 is of type A*.
 
0

0infinity0

Thx...
* (e-mail address removed):

That's a non-standard header.



'main' must have result type 'int'.



You're assigning to the pointer a1. Your operator only comes into play
if you assign to an object of type A. The pointer a1 is of type A*.




--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top