я взял код здесь:Invalid Static Cast
http://en.wikipedia.org/wiki/Variadic_template
Однако он рассматривает uint8_t и int8_t, как ASCII и поэтому я хочу, чтобы бросить все, что в int16_t. Я пытался сделать это:
template<typename T, typename... Args>
void log(const char *s, T value1, Args... args)
{
while (*s) {
if (*s == '%') {
if (*(s + 1) == '%') {
++s;
}
else {
if (std::is_same<T, uint8_t>::value || std::is_same<T, int8_t>::value)
{
int16_t x = value1;
int16_t x = static_cast<int16_t>(value1);
std::cout << x;
}
else
{
std::cout << value1;
}
log(s + 1, args...); // call even when *s == 0 to detect extra arguments
return;
}
}
std::cout << *s++;
}
throw std::logic_error("extra arguments provided to printf");
}
Однако я получил ошибку:
error: invalid static_cast from type ‘std::basic_string<char, std::char_traits<char>,
std::allocator<char> >’ to type ‘int16_t’
есть в любом случае, чтобы не печатать ASCII?
Проблема я вижу в том, что 'x' дважды объявлен. – gsamaras
Это два пути, которые я пытался использовать. Просто играю. Ошибка описана. Он не будет компилироваться. – user1876942
Ну код, который у вас есть в вашем вопросе, будет скомпилирован для меня, если имя второй 'x' как' x1'. – gsamaras