ho questo modello di classe:modelli variadic e nuova
template<class... T>
class Test {
std::vector<TestCase*> test_cases;
public:
Test() {
// Here, for each T an instance should be added to test_cases.
test_cases.push_back((new T)...);
}
};
Questo funziona bene per un argomento di template, ma per più argomenti ottengo questo errore:
error: too many arguments to function call, expected 1, have 2
Come posso utilizzare i modelli variadic con new
in questo modo? Qual è la sintassi corretta?
EDIT: Penso che la mia domanda non fosse abbastanza chiara. Quello che voglio è questo:
Test<TestCase1, TestCase2, TestCase3>;
// The constructor will then be:
test_cases.push_back(new TestCase1);
test_cases.push_back(new TestCase2);
test_cases.push_back(new TestCase3);
mio compilatore è 163.7.1 clang con questo flag: -std=c++0x
.
'std :: vector test_cases;' sembra strano poiché T è più di un tipo lì. –
Flexo
@awoodland hai ragione. Grazie per aver individuato questo. In effetti, ogni 'T' è una sottoclasse di' TestCase' (ecco perché uso i puntatori). Lo cambierò. –
Si potrebbe provare 'test_cases.push_back (new T()) ...;'. –