Errors on template with unsigned char
Hello,
I'm testing CLion, and I'm having troubles with errors check. I wrote some simple code to have a simple exemple:
#include <iostream>
#include <cstring>
class Table
{
public:
Table(unsigned int size)
{
_tab = new char[size];
memset(_tab, 0, size);
}
~Table()
{
delete [] _tab;
}
template <typename T>
T &at(unsigned int i)
{
T *t = static_cast<T *>(static_cast<void *>(_tab));
return t[i];
}
private:
char *_tab;
};
typedef unsigned char myuchar;
int main() {
Table tab(256);
for (unsigned int i = 0; i < 256; ++i) {
tab.at<unsigned char>(i) = static_cast<unsigned char>(i);
}
for (unsigned int i = 0; i < 256; ++i) {
std::cout << static_cast<int>(tab.at<myuchar>(i)) << std::endl;
}
return 0;
}
The problem here is that CLion reports an error on tab.at<unsigned char>(i) saying that it is expecting a '(' in the template. If I typedef unsigned char as I did a few lines under, the error isn't here anymore (using tab.at<myuchar>(i))
Of course this code compiles with no warning, and works as expected.
Am I doing something wrong or is it a problem with CLion's error check?
请先登录再写评论。