By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,329 Members | 1,674 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,329 IT Pros & Developers. It's quick & easy.

overload == operator for structure variables

P: n/a
Hi,

I have a class in which I have member variables for "timeb" structure. I
want to overload the operator == for the class. I want to check whether
2 structure variables are equal. How should I check whether 2 structure
variables are equal?

Please anybody could help.. I am pasting a small simple C++ code.

#include <string>
#include <vector>
#include <iostream>
#include <sys/timeb.h>

using namespace std;
int main()
{
timeb a, b;
// some code
vector<timeb> vecTime;
vecTime.push_back(a);
vecTime.push_back(b);

if (vecTime[0] == vecTime[1])
cout << "Equal";
else
cout << "Not equal";
return(0);
}

Jul 22 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a

"Sreeram" <sr*********@netscape.net> wrote in message
news:zU******************@cyclops.nntpserver.com.. .
Hi,

I have a class in which I have member variables for "timeb" structure. I
want to overload the operator == for the class. I want to check whether
2 structure variables are equal. How should I check whether 2 structure
variables are equal?

Please anybody could help.. I am pasting a small simple C++ code.

#include <string>
#include <vector>
#include <iostream>
#include <sys/timeb.h>

using namespace std;
int main()
{
timeb a, b;
// some code
vector<timeb> vecTime;
vecTime.push_back(a);
vecTime.push_back(b);

if (vecTime[0] == vecTime[1])
cout << "Equal";
else
cout << "Not equal";
return(0);
}


Like this

bool operator==(const timeb& lhs, const timeb& rhs)
{
// your code here
}

john
Jul 22 '05 #2

P: n/a
On Wed, 04 Aug 2004 17:08:53 +0530, Sreeram <sr*********@netscape.net>
wrote:
Hi,

I have a class in which I have member variables for "timeb" structure. I
want to overload the operator == for the class. I want to check whether
2 structure variables are equal. How should I check whether 2 structure
variables are equal?
By overloading operator== for the type.

Please anybody could help.. I am pasting a small simple C++ code.

#include <string>
#include <vector>
#include <iostream>
#include <sys/timeb.h>


inline bool operator==(timeb const& lhs, timeb const& rhs)
{
//do comparison, return true for equal.
}

Tom
Jul 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.