473,378 Members | 1,500 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,378 software developers and data experts.

overloading assignment operator

is it true that you cannot overload the assignment operator through a friend function?
please give a reason for your answer.
May 31 '07 #1
4 5084
sicarie
4,677 Expert Mod 4TB
is it true that you cannot overload the assignment operator through a friend function?
please give a reason for your answer.
What do you think? Have you tried writing a program that tries to do this?
May 31 '07 #2
Silent1Mezzo
208 100+
is it true that you cannot overload the assignment operator through a friend function?
please give a reason for your answer.
Sounds like a homework / test question
May 31 '07 #3
weaknessforcats
9,208 Expert Mod 8TB
The answer is: Yes.

A friend function is just a regular global function that has persomssion to access the class private data members. This has nothing to do with operator overloading.

An assignment operator inside a class has the "this" pointer as the first argument and a class object as the second argument. An assignment operator outside the class has two arguments. All overloading requires is that the function names be the same and the arguments are different.
May 31 '07 #4
The answer is: Yes.

A friend function is just a regular global function that has persomssion to access the class private data members. This has nothing to do with operator overloading.

An assignment operator inside a class has the "this" pointer as the first argument and a class object as the second argument. An assignment operator outside the class has two arguments. All overloading requires is that the function names be the same and the arguments are different.
Thank you for your reply. i came across this question in one of the past exam papers that i was going thru. i could not find a satisfying reason to explain to myself. thanks once again.
Jun 1 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

30
by: | last post by:
I have not posted to comp.lang.c++ (or comp.lang.c++.moderated) before. In general when I have a C++ question I look for answers in "The C++ Programming Language, Third Edition" by Stroustrup....
3
by: jim.brown | last post by:
The attached code implements a test class to show an error in overloading operator=. This code works on Windows with Visual Studio and simpler cases work with gcc 3.3.2 on Solaris 9. On Windows,...
2
by: Tony Johansson | last post by:
Hello!! Does anybody know what this mean If the base class defines a private overloaded assignment operator, the derived class must define this operator also. I know this about inheritance...
1
by: Jon Slaughter | last post by:
I have a chain of classes(i.e., a series of classes each containing an array of the next class). Each class has array like access. struct Myclass1 { vector(Myclass2) _Myclass2; Myclass2&...
12
by: Achim Domma | last post by:
Hi, I want to use Python to script some formulas in my application. The user should be able to write something like A = B * C where A,B,C are instances of some wrapper classes. Overloading...
9
by: sturlamolden | last post by:
Python allows the binding behaviour to be defined for descriptors, using the __set__ and __get__ methods. I think it would be a major advantage if this could be generalized to any object, by...
11
by: dascandy | last post by:
Hello, I was wondering, why is overloading operator. (period) forbidden? It would make a few odd applications possible (dynamic inheritance and transparent remote method invocation spring to my...
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...
3
by: Philipp Brune | last post by:
Hi all, i just played around a little with the c# operator overloading features and an idea came to my mind. You all possibly know the Nullable<T> Datatype. Now i thought it would be a nice idea...
8
by: Wayne Shu | last post by:
Hi everyone, I am reading B.S. 's TC++PL (special edition). When I read chapter 11 Operator Overloading, I have two questions. 1. In subsection 11.2.2 paragraph 1, B.S. wrote "In particular,...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.