template class
template< typename ... Args >
class Identifier: public std::tuple< Args... >
{
public:
Identifier( Args... args ):std::tuple< Args... >( std::forward< Args >( args )... )
{}
Identifier( std::tuple< Args... > tuple ):std::tuple< Args... >( tuple )
{}
Identifier()
{}
};
template< typename ...Args >
inline std::ostream& operator << ( std::ostream& os, Identifier< Args... > const& data )
{
os << "(";
/// here code to print Identifier items
os << ")";
return os;
}
when I try to print variable
Identifier<std::string, int64_t> item("str", 10);
std::cout<<item<<std::endl;
I've got a error multiple overloads of 'Identifier' instantiate to the same signature 'void ()'
If I remove constructor
Identifier()
{}
there is no error. But I need this constructor.
So how fix this error ?
template class
template< typename ... Args >
class Identifier: public std::tuple< Args... >
{
public:
Identifier( Args... args ):std::tuple< Args... >( std::forward< Args >( args )... )
{}
Identifier( std::tuple< Args... > tuple ):std::tuple< Args... >( tuple )
{}
Identifier()
{}
};
template< typename ...Args >
inline std::ostream& operator << ( std::ostream& os, Identifier< Args... > const& data )
{
os << "(";
/// here code to print Identifier items
os << ")";
return os;
}
when I try to print variable
Identifier<std::string, int64_t> item("str", 10);
std::cout<<item<<std::endl;
I've got a error multiple overloads of 'Identifier' instantiate to the same signature 'void ()'
If I remove constructor
Identifier()
{}
there is no error. But I need this constructor.
So how fix this error ?
Your main issue is that Identifier</*Empty*/>
has 2 default constructors.
You should restrict the varaidic one:
Identifier(Args... args) requires(sizeof...(Args) != 0) :
std::tuple<Args...>(std::forward< Args >(args)...)
{}
Demo
Not clear for me why std::cout<<item<<std::endl;
tries to instantiate Identifier</*Empty*/>
though.
Identifier
with no arguments. – Peter Commented Jan 31 at 7:30Identifier<>
needs to be instantiated -- and I don't know if it's worth my time to dig into that more.) – JaMiT Commented Jan 31 at 7:58item
and simply outputstd::cout<<std::endl;
. It's not "when I try to print variable" but when you streamstd::endl
while the definition ofIdentifier
is in scope. – JaMiT Commented Jan 31 at 8:10