rekahsoft
February 9th, 2007, 02:00 PM
Hi all i have been haviung an issue with operating overloading. I have been reading my C++ book and have came accross code that does not work. Here is an example://test.h
#ifndef __TEST_H
#include <string>
class Test {
friend bool operator==(const Test&, const Test&);
public:
bool operator==(const Test&, const Test&);
protected:
std::string test;
};
#endif
//test.cc
#include "test.h"
bool Test::operator==(const Test& a, const Test& b) {
return a.test == b.test;
}When i try to compile this with g++ i get the following error:bool Test::operator==(const Test&, const Test&) must take exactly one argumentThen when i define the example like so://test.h
#ifndef __TEST_H
#include <string>
class Test {
friend bool operator==(const Test&);
public:
bool operator==(const Test&);
protected:
std::string test;
};
#endif
//test.cc
#include "test.h"
bool Test::operator==(const Test& a) {
return this->test == b.test;
} i get the following error:bool Test::operator==(const Test&) must take exaclty two argumentThen when i define the class without the friend declaration it compiles. Can anybody explane what is happening here? This has thoroughly confused me. Thanks
#ifndef __TEST_H
#include <string>
class Test {
friend bool operator==(const Test&, const Test&);
public:
bool operator==(const Test&, const Test&);
protected:
std::string test;
};
#endif
//test.cc
#include "test.h"
bool Test::operator==(const Test& a, const Test& b) {
return a.test == b.test;
}When i try to compile this with g++ i get the following error:bool Test::operator==(const Test&, const Test&) must take exactly one argumentThen when i define the example like so://test.h
#ifndef __TEST_H
#include <string>
class Test {
friend bool operator==(const Test&);
public:
bool operator==(const Test&);
protected:
std::string test;
};
#endif
//test.cc
#include "test.h"
bool Test::operator==(const Test& a) {
return this->test == b.test;
} i get the following error:bool Test::operator==(const Test&) must take exaclty two argumentThen when i define the class without the friend declaration it compiles. Can anybody explane what is happening here? This has thoroughly confused me. Thanks