Я попытался создать обобщенный класс шаблона из трех кортежей, который принимает любой тип (int, double, unsigned char и т. д.), но у меня возникли проблемы с одной из функций-членов:
Код: Выделить всё
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 ) ;
};
'function': соответствующая перегруженная функция не найдена.
Я включил определения членов класса ниже, за которыми следует спецификация типа класса.
Код: Выделить всё
#include < striple.h >
template < typename structTypeA, typename structTypeB, typename structTypeC >
const structTypeA striple::getFir() { return first ; }
template< typename structTypeA, typename structTypeB, typename structTypeC >
const structTypeB striple::getSec() { return second ; }
template< typename structTypeA, typename structTypeB, typename structTypeC >
const structTypeC striple::getThir() { return third ; }
template< typename structTypeA, typename structTypeB, typename structTypeC >
template< typename memberOutType >
memberOutType striple::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::resetFirst(structTypeA resetter) { first = resetter ; }
template< typename structTypeA, typename structTypeB, typename structTypeC >
void striple::resetSecond( structTypeB resetter ) { second = resetter ;}
template< typename structTypeA, typename structTypeB, typename structTypeC >
void striple::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 brevity
Код: Выделить всё
int main() {
striple s = {1, 2, 3} ;
s.reset(0, 5)
std::cout
Подробнее здесь: [url]https://stackoverflow.com/questions/79872452/how-to-make-a-generalized-template-class[/url]
Мобильная версия