[英]Should I use pointer here?
讓我們創建三個類:
Class Vector3d:
class Vector3d{
int a,b,c;
}
Class Face,每個 Face 包含 3 個向量:
class Face{
Vector3d *a, *b, *c;
}
And class Mesh(3d object): in class mesh i can just get vector of faces, but most object of Vector3d class will be shared between many Faces so I`d like to store Vector3d in Mesh class and store only pointer in Face object;
class Mesh{
std::vector<Vector3d> points;
std::vector<Face> faces;
}
問題是,我不明白什么時候應該刪除 Face class 中的指針,我應該使用其他東西來代替這個嗎?
編輯:3 int 只是為了解釋我的概念,在最終版本中,Vector3d class 中會有更多數據
Face
應該存儲索引,而不是指針。
即Face
應該有三個成員:
unsigned a,b,c;
如果添加/刪除/調整Vector3d
向量的大小,索引是安全的。
它還允許您以更方便的方式在面之間共享點。
這也意味着您可以將faces
矢量的內容直接復制到圖形 API 緩沖區(采用授予類型匹配)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.