-6
我想知道如何動態地創建一個類數組,我試圖做一個如何創建類在C++動態數組
class A{
public:
int a;
int b;
}
main(){
A *temp;
temp[somevalue] = new (temp)
}
但問題是我不希望限制我的陣列someValue中我想擴展它,我想用std::vector
和std::lis
噸的,但我在執行卡住
我想知道如何動態地創建一個類數組,我試圖做一個如何創建類在C++動態數組
class A{
public:
int a;
int b;
}
main(){
A *temp;
temp[somevalue] = new (temp)
}
但問題是我不希望限制我的陣列someValue中我想擴展它,我想用std::vector
和std::lis
噸的,但我在執行卡住
的std::vector
簡單的例子:
class MyClass
{
public:
int A;
int B;
MyClass(int a, int b) : A(a), B(b) { }
};
std::vector<MyClass> temp;
temp.push_back(MyClass(1, 2));
temp.push_back(MyClass(3, 4));
// temp vector now contains two items
那你試試FO r'std :: vector'?這可能是你想要的。 – chris
你試過了std :: vector,但是你在實現中卡住了?武漢理工大學? – Borgleader
http://www.dreamincode.net/forums/topic/63358-store-class-objects-in-vector/ – OldProgrammer