Solved

adding = and == to my class

Posted on 2006-06-26
2
190 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
  • 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 50 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
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 tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

948 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now