ARTICLE AD BOX
I've done some amateur object-oriented programming in C++ and I have a quick question of what is possible when creating your own class.
I've attempted to make a generalized 3-tuple template class that accepts any type (int, double, unsigned char, etc.), but I am having trouble with one of the member functions:
template< typename structTypeA, typename structTypeB, typename structTypeC > class striple { private : structTypeA first ; structTypeB second ; structTypeC third ; public : striple( ) : first { }, second { }, third{ } { } striple( structTypeA firSetter ) : first { firSetter }, second { }, third{ } { } striple( structTypeA firSetter, structTypeB secSetter ) : first { firSetter }, second { secSetter }, third{ } { } striple( structTypeA firSetter, structTypeB secSetter, structTypeC thirSetter ) : first { firSetter }, second { secSetter }, third{ thirSetter } { } const structTypeA getFir ( ) ; const structTypeB getSec ( ) ; const structTypeC getThir ( ) ; template< typename memberOutType > memberOutType get( const unsigned char INDEX ) ; void resetFirst ( structTypeA resetter ) ; void resetSecond ( structTypeB resetter ) ; void resetThird ( structTypeC resetter ) ; template< typename memberInType > void reset( const unsigned char INDEX, const memberInType& resetter ) ; };Everything works except the member function "reset" - it causes the Compiler Error C2672
'function': no matching overloaded function found
I have included the class member definitions below - followed by the type specification of the class.
#include < striple.h > template < typename structTypeA, typename structTypeB, typename structTypeC > const structTypeA striple<structTypeA, structTypeB, structTypeC>::getFir() { return first ; } template< typename structTypeA, typename structTypeB, typename structTypeC > const structTypeB striple<structTypeA, structTypeB, structTypeC>::getSec() { return second ; } template< typename structTypeA, typename structTypeB, typename structTypeC > const structTypeC striple<structTypeA, structTypeB, structTypeC>::getThir() { return third ; } template< typename structTypeA, typename structTypeB, typename structTypeC > template< typename memberOutType > memberOutType striple<structTypeA, structTypeB, structTypeC>::get( const unsigned char INDEX ) { switch( INDEX ) { case ITEM::FIRST : return first ; case ITEM::SECOND : return second ; case ITEM::THIRD : return third ; } } template< typename structTypeA, typename structTypeB, typename structTypeC > void striple<structTypeA, structTypeB, structTypeC>::resetFirst(structTypeA resetter) { first = resetter ; } template< typename structTypeA, typename structTypeB, typename structTypeC > void striple<structTypeA, structTypeB, structTypeC>::resetSecond( structTypeB resetter ) { second = resetter ;} template< typename structTypeA, typename structTypeB, typename structTypeC > void striple<structTypeA, structTypeB, structTypeC>::resetThird( structTypeC resetter ) { third = resetter ; } template class striple< short unsigned , short unsigned , short unsigned > ; template class striple< unsigned , unsigned , unsigned > ; template class striple< long unsigned , long unsigned , long unsigned > ; template class striple< long long unsigned , long long unsigned , long long unsigned > ; template class striple< short int , short int , short int > ; template class striple< int , int , int > ; template class striple< long int , long int , long int > ; template class striple< long long int , long long int , long long int > ; template class striple< float , float , float > ; template class striple< double , double , double > ; template class striple< long double , long double , long double > ; template class striple< short unsigned , short unsigned , short unsigned > ; template class striple< unsigned , unsigned , unsigned > ; template class striple< long unsigned , long unsigned , long unsigned > ; template class striple< long long unsigned , long long unsigned , long long unsigned > ; template class striple< short int , short int , short int > ; template class striple< int , int , int > ; template class striple< long int , long int , long int > ; template class striple< long long int , long long int , long long int > ; //The remaining specifications have been omitted for brevityHere is main with a simple attempt to reset one of the items in the vector and display the result:
int main() { striple s = {1, 2, 3} ; s.reset(0, 5) std::cout << s.get(0) ;I have no idea how to fix this. Any help doing so would be greatly appreciated.
