Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

adding = and == to my class

Posted on 2006-06-26
2
Medium Priority
?
202 Views
Last Modified: 2010-04-01
I have a class thats really just a simple vector class called record that I use for a very specific function in a project I am working on, now it has a private int array value,
I want to be able to do this basically,

record a,b;
a.set(1,2,3,5);
b.set (3,2,5,1);
//where set just gives the private int array the values given as arguements
a=b;<-- this is the part I can't figure out, how do I add = to  my  list of class functions
and also
if(a==b)
 execute such and such code.

I can't find this anywhere on the internet, I believe because I don't know what to search for exactly, if anyone could help me out with this I would be greatly appreciative.
0
Comment
Question by:am3081
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 12

Expert Comment

by:rajeev_devin
ID: 16989926
Implement the operators given below

class record {
public:
      record& operator= (const record& r);
      bool operator== (const record& r);
};
0
 
LVL 12

Accepted Solution

by:
rajeev_devin earned 200 total points
ID: 16989930
record& operator= (const record& r); // assignment operator
Ex:
a=b;

bool operator== (const record& r); // equal operator
Ex:
if(a==b)
{
}
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question