using T& operator*(T*);

S

sandSpiderX

Hi,

How do i use this definition of overloaded operator,
T& operator*(T*);
like

struct X {};

X ox;
X* px=&ox;
X oy;

oy=*px;

is this correct use of this operator overload.

Help
SS
 
J

John Carson

sandSpiderX said:
Hi,

How do i use this definition of overloaded operator,
T& operator*(T*);
like

struct X {};

X ox;
X* px=&ox;
X oy;

oy=*px;

is this correct use of this operator overload.


No, it is not even close. You can't guess this stuff, but it is explained in
any number of textbooks. You should be working through one.
 
R

Rolf Magnus

sandSpiderX said:
Hi,

How do i use this definition of overloaded operator,
T& operator*(T*);

You cannot overload this operator. T* is a built-in type, and operators that
only have built-in types as parameters cannot be user-defined.
 
S

sandSpiderX

Hi, Rolf,

This is confusing....

operators that only have built-in types as parameters cannot be
user-defined.

However, this is the goal of operator overloading. Every operator which
is overloaded has built in type as parameters or operands.

AFAIK, this is the central core to operator overloading....to enable
operators work on user defined types which have only operands as built
in types...

Suggest
sandSpiderX.
 
R

Rolf Magnus

sandSpiderX said:
Hi, Rolf,

This is confusing....

operators that only have built-in types as parameters cannot be
user-defined.

However, this is the goal of operator overloading.

No, it isn't. The goal is to extend the behavior of C++ with user-defined
types, not to modify the built-in behavior.
Every operator which is overloaded has built in type as parameters or
operands.

No. You can only overload operators for user-defined types.
AFAIK, this is the central core to operator overloading....to enable
operators work on user defined types which have only operands as built
in types...

No. The parameters are what is used to select a specific operator. If those
are only built-in types, how would the compiler know that you do not want
the built-in operator but the other one? Which is more or less the question
you were initially asking for.
 

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

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,681
Members
48,796
Latest member
Greg L.

Latest Threads

Top