Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
テンプレートを使用して合計を見つけるように言われました。なぜこれが機能しないのですか?ありがとう。
template <typename A, typename B, typename C> auto add(A a, B b, C c = a + b) -> decltype(c) { return c; }
C++ 11 では、引数を宣言した後に使用できると言っていると思いました。なぜこれがうまくいかないのですか?
デフォルトの値として引数を使用することはできません。また、テンプレートの型推論はそのようには機能しません。
次のように書くだけです:
template <typename A, typename B> auto add(A a, B b) -> decltype(a + b) { return a + b; }
そして、C++ がすぐに戻り値の型推論を取得することを願っています。