1
クラス宣言の内側と外側の両方で、variadicクラスのフレンドにテンプレート関数をどのように宣言しますか?variadicクラスにテンプレートフレンド関数を宣言する方法
たとえば、これは私がクラス宣言の中に書くと思いますが、定義されていない参照エラーが発生しています。
#include <tuple>
#include <vector>
namespace ns
{
template<class...>
class Example;
template<class A, class... Bs>
std::vector<A>& get(Example<Bs...>& pExample);
template<class... As>
class Example
{
private:
std::tuple<std::vector<As>...> mVectors;
public:
explicit Example(std::size_t pCapacity)
: mVectors(std::vector<As>(pCapacity)...)
{}
template<class B> //Error: undefined reference to `std::vector<int,std::allocator<int> >& ns::get<int, int, float>(ns::Example<int, float>&)
friend std::vector<B>& get(Example<As...>& pExample)
{
return std::get<std::vector<B>>(pExample.mVectors);
}
};
}
あなたは(http://rextester.com/RPTTEM53254)[私のためにコンパイル]を示したコード。問題がある限り、それはあなたが示していないコードの中にある必要があります。 [MCVE](https://stackoverflow.com/help/mcve)を準備します。 –
関数が使用されないためコンパイルされることがあります。 'ns :: Example example(100);の主な機能のほかに、 std :: vector &ref = ns :: get (例);これは私が書いた唯一のコードです。 –
Brian