0
目前編程專業標準庫,而且我發現,在特定的情況下,這是必要的我:C++:重載模板別名
namespace std
{
// key, value
template<class K, class V>
using vector_map = other_namespace::vector_map<K, V>;
// key, value, compare
template<class K, class V, class C>
using vector_map = other_namespace::vector_map<K, V, C>;
}
它,然而,無法正常工作。不奇怪。但是,我有什麼選擇來實現這一目標? 我曾想過使用預處理器,但我想知道你們的想法。
我希望能夠選擇性別名模板類到另一個名稱空間,如果可能的話。
解決方案(在我的情況)是增加而不是有幾個usings默認值:
namespace std
{
// key, value, compare
template<class K, class V, class C = default_value>
using vector_map = other_namespace::vector_map<K, V, C>;
}
你想達到什麼目的? 'other_namespace :: vector_map'也不是「重載」的,它只有'C'的默認值。那也能爲你工作嗎? – Cameron 2014-10-08 22:12:34
我想要具有相同的功能,就好像模板類本身與我的using語句位於同一名稱空間中一樣。在此示例中,vector_map位於other_namespace中,但我想將特定變體移動到std :: namespace:和類型。 –
gonzo
2014-10-08 22:15:01
是的,謝謝!我只是將默認值添加到我的模板別名,並解決它。再次感謝 – gonzo 2014-10-08 22:20:02