473,698 Members | 2,635 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 5086
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=(co nst 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************ **********@c13g 2000cwb.googleg roups.com>,
George <ge**********@e xcite.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
1805
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 assignment, should copy constructor and assignment operator be unnecessary? 2. If a base class have a pointer member, should its derived classes also need copy constructor and assignment operator, no matter if a derived class itself has a...
5
3282
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 assignment Student* john = michael; both john and michael share the same object. This type of an assignment is different then value-assignmnet semantics used by class variables, as in
9
2081
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 emulate the pattern im trying to follow in an existing project. These are my steps: 1) I have a method "printMe" existing in the application which originally used to take in a string. This method is static and sits in the Driver
25
2047
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; x.SomethingElse = 5; x = 4;
36
3626
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 in a C# program but not VB? -- Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/ "Programming is an art form that fights back"
10
2569
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, we do not need to use the copy-constructor. So depending on the above reasoning I can avoid call by value and return by value for class objects, this bypasses the problem or it seems to me like that. Could any one give me some simple examples...
22
3613
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 v);
13
3963
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 is much appreciated. JD
9
2890
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 Foo() is included, i believe. };
0
8683
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8610
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9170
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9031
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8902
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6528
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4623
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2339
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.