Created
December 1, 2012 23:26
-
-
Save drewverlee/4185901 to your computer and use it in GitHub Desktop.
trying to do problem b, getting the following errors, not examples in the book. Not sure if small syntax issue or something larger.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26.cpp|30 col 6 error| ‘template<class type> class strange’ used without template parameters | |
26.cpp|30 col 32 error| invalid use of template-name ‘strange’ without an argument list | |
26.cpp|30 col 41 error| ISO C++ forbids declaration of ‘rightObject’ with no type [-fpermissive] | |
26.cpp|30 col 52 error| ‘bool operator==(const int&)’ must have an argument of class or enumerated type | |
//a.Write a statement that declares sObj to be an object of type strange | |
//such that the private member variables a and b are of type int. | |
//b. Write a statement that shows the declaration in the class strange to | |
//overload the operator == as a member function. | |
//c. Assume that two objects of type strange are equal if their correspond- | |
//ing member variables are equal. Write the definition of the function | |
//operator== for the class strange, which is overloaded as a | |
//member function. | |
// | |
//Consider the following declaration: | |
#include <iostream> | |
using namespace std; | |
template <class type> | |
class strange | |
{ | |
public: | |
/* -----------------$$( functions )$$-----------------*/ | |
/* b */ | |
bool operator==(const strange& rightObject ) const; | |
private: | |
/* -----------------$$( data members )$$-----------------*/ | |
type a; | |
type b; | |
};/* ------- END OF strange ------------ */ | |
/* function */ | |
template <class type> | |
bool strange::operator==(const strange& rightObject) | |
{ | |
return (strange.a == rightObject.a && strange.b == rightObject.b); | |
} | |
/* main ----------- */ | |
//int main() | |
//{ | |
// /* a */ | |
// strange<int> sObj; | |
//}/* ------- END OF main ------------ */ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
what is the solution