回答編集履歴
2
コード修正
answer
CHANGED
@@ -8,7 +8,7 @@
|
|
8
8
|
|
9
9
|
```
|
10
10
|
template <typename... Args>
|
11
|
-
Draw(const glm::vec2 pos, const char* font, unsigned short pixel,
|
11
|
+
void Draw(const glm::vec2 pos, const char* font, unsigned short pixel,
|
12
12
|
const glm::vec4 color, const char *str, const Args&... args) {
|
13
13
|
...
|
14
14
|
std::format(str, args...);
|
1
文言
answer
CHANGED
@@ -2,13 +2,14 @@
|
|
2
2
|
|
3
3
|
[前の質問](https://teratail.com/questions/345714)と同様に、可変長引数 `...` の関数から[可変引数テンプレート](https://cpprefjp.github.io/lang/cpp11/variadic_templates.html) `const T&... args` の関数を呼ぶことは不可能だと思います。
|
4
4
|
|
5
|
-
`std::vformat()`というのもありますが、これは`va_list`を引数に取るわけではないので、やはり `Text::Draw()`から呼ぶことはできません。
|
5
|
+
`std::vformat()`というのもありますが、これは`va_list`を引数に取るわけではないので、やはり今のままでは `Text::Draw()`から呼ぶことはできません。
|
6
6
|
|
7
7
|
思いつく対処は、`Text::Draw()`を可変引数テンプレートに書き換えて、引数を展開するか `std::forward()` で `std::format()` にわたすことです。
|
8
8
|
|
9
9
|
```
|
10
10
|
template <typename... Args>
|
11
|
+
Draw(const glm::vec2 pos, const char* font, unsigned short pixel,
|
11
|
-
|
12
|
+
const glm::vec4 color, const char *str, const Args&... args) {
|
12
13
|
...
|
13
14
|
std::format(str, args...);
|
14
15
|
```
|