Here is MCVE of my problem:
#include <cstdlib>
#include <cstdint>
template<std::size_t CAPACITY>
class Buffer
{
public:
template<std::size_t PARAM_SIZE>
void pushArray(const uint8_t values[PARAM_SIZE])
{
// method's body (not important)
}
};
template<std::size_t CAPACITY>
class BetterBuffer : public Buffer<CAPACITY>
{
public:
template<typename TYPE>
void push(TYPE value)
{
typedef uint8_t arrayType_t[sizeof(TYPE)];
const arrayType_t &array = (arrayType_t&)value;
Buffer<CAPACITY>::pushArray<sizeof(TYPE)>(array);
}
};
int main()
{
BetterBuffer<10> buffer;
buffer.push(100);
return 0;
}
The compiler prints the following error message.
main.cpp: In instantiation of ‘void BetterBuffer<CAPACITY>::push(TYPE) [with TYPE = int; long unsigned int CAPACITY = 10]’:
main.cpp:31:24: required from here
main.cpp:24:40: error: invalid operands of types ‘<unresolved overloaded function type>’ and ‘long unsigned int’ to binary ‘operator<’
Buffer<CAPACITY>::pushArray<sizeof(TYPE)>(array);
~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
I compile it with command g++ -Wall -std=c++17 main.cpp
.
I'm using g++ in version: 'g++ (Ubuntu 7.1.0-5ubuntu2~16.04) 7.1.0'.
If I remove the template parameter from class Buffer
or move the method push
from BetterBuffer
to Buffer
then program can compile with no problem.
What is wrong with this specific code?