This question already has an answer here:
I would like help understanding this gcc compilation error. The following c++ code is for what I thought was a relatively simple class which will hold some data and use a metadata class (which will act like a traits class).
template < class METADATA_TYPE, class VALUE_TYPE>
class DataMetadata
{
public:
DataMetadata() {}
DataMetadata(VALUE_TYPE v) : m_v(v) {}
template<class U, class V>
DataMetadata(const DataMetadata<U, V> &other)
{
m_v = other.value<METADATA_TYPE>();
}
template<class U, class V>
void assignFrom(const DataMetadata<U, V> &other)
{
m_v = other.value<METADATA_TYPE>();
}
template <class REQUIRED_METADATA_TYPE>
VALUE_TYPE value() const
{
//some conversion will happen here based on METADATA_TYPE AND REQUIRED_METADATA_TYPE
//for the purposes of creating a minimal example it has been removed
return m_v;
}
private:
VALUE_TYPE m_v;
};
I put the above code in a file MetaMinimal.cpp
, and compiled with gcc giving the following compile errors
$ gcc MetaMinimal.cpp
MetaMinimal.cpp: In constructor ‘DataMetadata<METADATA_TYPE, VALUE_TYPE>::DataMetadata(const DataMetadata<U, V>&)’:
MetaMinimal.cpp:10:48: error: expected primary-expression before ‘>’ token
m_v = other.value<METADATA_TYPE>();
^
MetaMinimal.cpp:10:50: error: expected primary-expression before ‘)’ token
m_v = other.value<METADATA_TYPE>();
^
MetaMinimal.cpp: In member function ‘void DataMetadata<METADATA_TYPE, VALUE_TYPE>::assignFrom(const DataMetadata<U, V>&
’:
MetaMinimal.cpp:15:48: error: expected primary-expression before ‘>’ token
m_v = other.value<METADATA_TYPE>();
^
MetaMinimal.cpp:15:50: error: expected primary-expression before ‘)’ token
m_v = other.value<METADATA_TYPE>();
^
Googling the error gives a number of things regarding passing classes/types into functions instead of objects/values or missing brackets. But I can't see how that this applies here.