473,402 Members | 2,050 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

implicit copy assignment operator

Dear C++ Afficionados,

I know the compiler will generate a copy assignment operator (amongst
other fn's) if you don't provide one in your class declaration.

But the parameter types can vary, and the compiler decides between
const, reference, and (with xlC) volatile.

Is there any way to dump the object file and see what the compiler
generated? I couldn't see any switches for this. It would be helpful
to see I think.

Thanks much. Sincerely, George

Jul 23 '05 #1
6 5069
Better to just define your own. That way you know what you're getting.

Jul 23 '05 #2

George wrote:
Dear C++ Afficionados,

I know the compiler will generate a copy assignment operator (amongst
other fn's) if you don't provide one in your class declaration.

But the parameter types can vary, and the compiler decides between
const, reference, and (with xlC) volatile.

Is there any way to dump the object file and see what the compiler
generated? I couldn't see any switches for this. It would be helpful to see I think.

Thanks much. Sincerely, George


Jul 23 '05 #3
George wrote:
I know [that] the compiler will generate a copy assignment operator
(among other functions)
if you don't provide one in your class declaration.
No. For class X, yhe compiler will supply

1. an assignment operator,

X& X::operator=(const X&);

2. a *default* constructor

X::X(void);

3. ans a copy constructor

X::X(const X&);

by default.
But the parameter types can vary,
If you need an assignment operator or default constructor
which accepts any arguments other that those above,
you must define them yourself.
and the compiler decides between
const, reference, and (with xlC) volatile.

Is there any way to dump the object file
and see what the compiler generated?


The typical compiler
never actually creates callable functions for them
but inlines them automatically.
Jul 23 '05 #4
I did,

T& operator=(const T&)

But the compiler wouldn't take it. So after several attempts, it was
happy without the const and the &.

There are 5 possible signatures, (at least with xlC). I suppose the
best solution is to define all 5.

-g

Jul 23 '05 #5
In message <11**********************@c13g2000cwb.googlegroups .com>,
George <ge**********@excite.com> writes
I did,

T& operator=(const T&)

But the compiler wouldn't take it.
?? It should take whatever you give it.

Post actual code, and the compiler's error messages.
So after several attempts, it was
happy without the const and the &.
Which would imply taking a copy before you perform the assignment.
There are 5 possible signatures, (at least with xlC). I suppose the
best solution is to define all 5.

No. The best solution is to say what you mean.

--
Richard Herring
Jul 23 '05 #6
Oops, my bad. "An rvalue cannot be converted to a reference to a
non-const type."

I'd overlooked that compiler message.

Thanks for all the help. Sincerely,

George

---------------------------------------------------------------------
// This fails to compile, messages are:
//
// The call does not match any parameter list for "operator="
// "P::operator=(P&)" is not a viable candidate.
// A parameter of type "P&" cannot e initalized with an rvalue of type
"P"
// An rvalue cannot be converted to a reference to a non-const type
//
// Compile with xlC -c <thisfile>

class P{
public:

explicit P(int i);
P(P& p);
P& operator=(P&);
void swishswish();
private:
int data;
};
inline P::P(int i) : data(i){ }
inline P::P(P& p):data(p.data) { }
inline P& P::operator=(P& p){ data = p.data; return *this;}
void P::swishswish(){ data = 89; }

int main()
{
P iP(2);
iP = static_cast<P>(3);
iP.swishswish();

return 0;
}

Jul 23 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: away | last post by:
1. When a class defined with a member of pointer type, it's necessary to have a copy constructor and assignment operator. If don't pass objects of such class as value in a function and don't do...
5
by: Tony Johansson | last post by:
Hello! I'm reading in a book about C++ and that is something that sound strange. It says "Pointers have reference-assignment semantics similar to those in Java. For example, after the...
9
by: Girish | last post by:
Im trying to understand implicit type conversions from object -> string and vice versa. I have two classes, one Driver and one called StringWrapper. These are just test classes that try and...
25
by: Chad Z. Hower aka Kudzu | last post by:
I have defined some implicit convertors so that I can do: MyStruct x = 4; The implicit convert the 4 into MyStruct. But its essentially a copy constructor and thus if I had: MyStruct x;...
36
by: Chad Z. Hower aka Kudzu | last post by:
I have an implicit conversion set up in an assembly from a Stream to something else. In C#, it works. In VB it does not. Does VB support implicit conversions? And if so any idea why it would work...
10
by: utab | last post by:
Dear all, So passing and returning a class object is the time when to include the definition of the copy constructor into the class definition. But if we don't call by value or return by value, ...
22
by: clicwar | last post by:
A simple program with operator overloading and copy constructor: #include <iostream> #include <string> using namespace std; class Vector { private: float x,y; public: Vector(float u, float...
13
by: JD | last post by:
Hi, My associate has written a copy constructor for a class. Now I need to add an operator = to the class. Is there a way to do it without change her code (copy constructor) at all? Your help...
9
by: puzzlecracker | last post by:
From my understanding, if you declare any sort of constructors, (excluding copy ctor), the default will not be included by default. Is this correct? class Foo{ public: Foo(int); // no...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.