Re: [問題] 二維陣列、vector 函式傳遞
看板C_and_CPP (C/C++)作者rodion (去看二輪Liar Game!)時間14年前 (2012/03/14 18:29)推噓0(0推 0噓 0→)留言0則, 0人參與討論串2/2 (看更多)
分享一下我的想法~
現在還不支援以 a[x][y] 存取,
但加入operator[] 實作 getValue就很容易做到了
以下是介面部分~ 實作部分應該不困難~ 有須要在來討論
class InnerElement
{
public:
InnerElement():_innerElements(gPredefinedInnerSize) {}
~InnerElement();
// manipulators
bool setValue(const void* element, int index);
// accessors
const void* getValue(int index) const;
private:
vector<const void*> _innerElements;
};
class OuterElement
{
public:
OuterElement():_outerElement(gPredefinedOuterSize) {}
~OuterElement();
// manipulators
bool setValue(const void* element, int indexX, int indexY);
// accesors
const void* getValue(int indexX, int indexY) const;
private:
vector<InnerElement*> _outerElements;
};
class 2DVector
{
public:
2DVector() {}
// manipulators
bool setValue(const void* element, uint indexX, uint indexY);
// accessors
const void* getValue(uint indexX, uint indexY) const;
private:
OuterElement _outerArray;
};
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 220.128.66.129
※ 編輯: rodion 來自: 220.128.66.129 (03/14 18:37)
※ 編輯: rodion 來自: 220.128.66.129 (03/14 18:37)
討論串 (同標題文章)
完整討論串 (本文為第 2 之 2 篇):
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章