📜  c++ 类对象的向量 - C++ 代码示例

📅  最后修改于: 2022-03-11 14:44:50.075000             🧑  作者: Mango

代码示例1
#include 
#include 
using namespace std;

class Site {
public:
    int i;
};

int main() {
    vector listofsites;
    Site *s1 = new Site;
    s1->i = 7;
    Site *s2 = new Site;
    s2->i = 9;
    listofsites.push_back(*s1);
    listofsites.push_back(*s2);
    vector::iterator it;
    for (it = listofsites.begin(); it != listofsites.end(); ++it) {
        cout << it->i;
    }
    return 0;
}