我有结构KhoiGach。我设计了功能" KhoiGach * TaoKhoiGach" for return 1变量,数据类型" KhoiGach"但它失败了
struct KhoiGach
{
int **arr;
int Row,Col;
int iBoard,jBoard;
};
class DesignBrick
{
public:
DesignBrick();
virtual ~DesignBrick();
int Board[MaxI][MaxJ];
KhoiGach pkhoigach;
KhoiGach *TaoKhoiGach(int ID);
};
KhoiGach DesignBrick :: *TaoKhoiGach(int ID)
{
KhoiGach *pkhoigach;
pkhoigach = new KhoiGach;
return &pkhoigach;
}
答案 0 :(得分:0)
这里:
KhoiGach DesignBrick :: *TaoKhoiGach(int ID)
如果要返回指针KhoiGach
,则需要将其更改为:
KhoiGach *DesignBrick :: TaoKhoiGach(int ID)
在这里:
return &pkhoigach;
你要返回指针的地址,它与你的函数返回值不匹配(我仍假设你要返回指向KhoiGach
的指针)
你想要这个:
return pkhoigach;