Я хотел бы создать строки с компиляцией с помощью пользовательского макета.#include
#include
#include
template<
std::size_t Size,
typename CharType
>
struct string_literal
{
std::array chars;
constexpr string_literal(CharType(&literal_array)[Size]) :
chars(std::to_array(literal_array))
{
}
//causes an error with g++
virtual void Foo(){}
constexpr ~string_literal(){}
};
template
constexpr auto* operator ""_s()
{
return &std::integral_constant::value;
}
int main(){
auto x = u"Hello world"_s;
return 0;
}
< /code>
Он ломается на g ++, когда я добавляю виртуальную функцию, поэтому мой вопрос: разве это не разрешено или это G ++-ошибка (она компилируется с Clang, MSVC и Intel-компилятором)? < /p>
Фактическое сообщение об ошибке: < /p>
< /p>
Сообщение об ошибке: < /p>
< /p>
: In function 'int main()':
:32:14: error: no matching function for call to 'operator""_s()'
32 | auto x = u"Hello world"_s;
| ^~~~~~~~~~~~~~~~
:32:14: note: there is 1 candidate
:26:17: note: candidate 1: 'template constexpr auto* operator""_s()'
26 | constexpr auto* operator ""_s()
| ^~~~~~~~
:26:17: note: template argument deduction/substitution failed:
:32:14: error: '((& string_literal::_ZTV14string_literalILm12EKDsE) + 16)' is not a valid template argument for 'int (**)(...)' because it is not the address of a variable
32 | auto x = u"Hello world"_s;
| ^~~~~~~~~~~~~~~~
< /code>
Здесь более упрощенная версия задачи: < /p>
class Foo{
virtual void Bar(){
}
};
template
void XXX(){
}
int main(){
constexpr static auto foo = Foo();
XXX();
return 0;
}
Подробнее здесь: https://stackoverflow.com/questions/797 ... late-argum
Разрешены ли виртуальные функции для скалярных типов - используются в качестве аргумента шаблона без типа ⇐ C++
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение