overload == operator for structure variables

S

Sreeram

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);
}
 
J

John Harrison

Sreeram said:
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
 
T

tom_usenet

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top