Macro var args

T

TheDD

red said:
Why are you using new? Why not just:
throw Class args << Location(__FILE__, __LINE__)
[redacted]
43
44 template <typename T>
45 class Ex_ : public Ex
46 {
47 public:
48 T & operator << (Location * loc)
T& operator << (const Location& loc)
49 {
50 this->loc = *loc; this->loc = loc;
51 delete loc;
// delete loc; // line not needed.
52
53 T * real = dynamic_cast<T *>(this);
54 assert(real);
55 return *real;
56 }
57 };
58
[redacted]

thx, i've changed my code, but i used to think that in c++ you can't do:

obj.method(Class(args));

but

Class c(args);
obj.method(c);

so i thought i was the same in the case of << (don't understand why it's
not)

BTW, i don't know the rationale of that.
 
V

Victor Bazarov

TheDD said:
red said:
Why are you using new? Why not just:
throw Class args << Location(__FILE__, __LINE__)
[redacted]
43
44 template <typename T>
45 class Ex_ : public Ex
46 {
47 public:
48 T & operator << (Location * loc)
T& operator << (const Location& loc)
49 {
50 this->loc = *loc; this->loc = loc;
51 delete loc;
// delete loc; // line not needed.
52
53 T * real = dynamic_cast<T *>(this);
54 assert(real);
55 return *real;
56 }
57 };
58
[redacted]

thx, i've changed my code, but i used to think that in c++ you can't do:

obj.method(Class(args));

but

Class c(args);
obj.method(c);

so i thought i was the same in the case of << (don't understand why it's
not)

BTW, i don't know the rationale of that.

Class(args) is a temporary. If your operator<< accepts a non-const
reference as its left operand, then you cannot say

Class(args) << blah

because binding a non-const reference to a temporary is prohibited.

Or maybe I am completely off and you're asking about something else,
then sorry for being too inattentive.

Victor
 
V

Victor Bazarov

TheDD said:
red said:
Why are you using new? Why not just:
throw Class args << Location(__FILE__, __LINE__)
[redacted]
43
44 template <typename T>
45 class Ex_ : public Ex
46 {
47 public:
48 T & operator << (Location * loc)
T& operator << (const Location& loc)
49 {
50 this->loc = *loc; this->loc = loc;
51 delete loc;
// delete loc; // line not needed.
52
53 T * real = dynamic_cast<T *>(this);
54 assert(real);
55 return *real;
56 }
57 };
58
[redacted]

thx, i've changed my code, but i used to think that in c++ you can't do:

obj.method(Class(args));

but

Class c(args);
obj.method(c);

so i thought i was the same in the case of << (don't understand why it's
not)

BTW, i don't know the rationale of that.

Class(args) is a temporary. If your operator<< accepts a non-const
reference as its left operand, then you cannot say

Class(args) << blah

because binding a non-const reference to a temporary is prohibited.

Or maybe I am completely off and you're asking about something else,
then sorry for being too inattentive.

Victor
 
T

TheDD

Class(args) is a temporary. If your operator<< accepts a non-const
reference as its left operand, then you cannot say

Class(args) << blah

because binding a non-const reference to a temporary is prohibited.

Thx for the tip
Or maybe I am completely off and you're asking about something else,
then sorry for being too inattentive.

Well, what about the right operand? Same rules apply?
 
V

Victor Bazarov

TheDD said:
Le 27/05/2004 à 04:18:11, Victor Bazarov <[email protected]> a
écrit:




Thx for the tip




Well, what about the right operand? Same rules apply?

Yes, however, it is customary to have the right operand of operator<<
a const reference anyway. Rarely is it needed to not have it const.

Victor
 
R

red floyd

TheDD said:
Thx for the tip


Well, what about the right operand? Same rules apply?

Yeah. Temps can only be thrown around via value or const reference.

What about

friend Ex_ operator<< (const Ex_&, const Location&)

(note that the return value is an Ex_, not an Ex_&!)
 
T

TheDD

Le 27/05/2004 à 19:30:15 said:
Yeah. Temps can only be thrown around via value or const reference.

What about

friend Ex_ operator<< (const Ex_&, const Location&)

(note that the return value is an Ex_, not an Ex_&!)

I've tried something like that but the << operator can take only one
argument (it's the rationale for my Location class).
 
V

Victor Bazarov

TheDD said:
I've tried something like that but the << operator can take only one
argument (it's the rationale for my Location class).

That's only true if your operator << is a member. 'red floyd' showed
the declaration of a stand-alone operator <<, IIUIC.

V
 

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
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top