[問題] 關於member function回傳問題
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
Code::Blocks
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
問題(Question):
先自己寫一個class Vec ,裡面有一個member function inpendentSet()
在主程式需要可以執行以下:
Vec vec1;
Vec vec2;
vec1 = vec2.inpendentSet();
想問這樣在class裡應該要如何寫,inpendentSet()回傳型態必須要自己本身的物件
餵入的資料(Input):
預期的正確結果(Expected Output):
錯誤結果(Wrong Output):
程式碼(Code):(請善用置底文網頁, 記得排版)
我把它寫成底下這樣
class Vec
{
int *array;
int dim;
public:
Vec();
Vec(int *row, int n);
Vec inpendetSet();
};
Vec::Vec()
{
.....
}
Vec::Vec(int *row, int n)
{
.....
}
Vec Vec::inpendetSet()
{
Vec NewArray;
.....
.....
return NewArray;
}
int main()
{
.....
.....
Vec vec1;
.....(vec1已經有值)
Vec vec2;
vec2 = vec1.inpendentSet();
}
我這樣寫好像不行,compile會過,但執行出來會有錯誤然後當掉。
補充說明(Supplement):
C++新手,拜託各位大大解答,感謝><
補上完整程式碼:http://codepad.org/jtzdv7lI
感謝大家qq
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 120.127.224.113
※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1464268394.A.A41.html
→
05/26 21:19, , 1F
05/26 21:19, 1F
推
05/26 21:46, , 2F
05/26 21:46, 2F
→
05/26 21:46, , 3F
05/26 21:46, 3F
→
05/26 21:48, , 4F
05/26 21:48, 4F
噓
05/26 22:12, , 5F
05/26 22:12, 5F
推
05/26 22:14, , 6F
05/26 22:14, 6F
→
05/26 22:15, , 7F
05/26 22:15, 7F
→
05/26 22:22, , 8F
05/26 22:22, 8F
※ 編輯: nick982009 (120.127.224.113), 05/26/2016 22:39:45
→
05/26 22:50, , 9F
05/26 22:50, 9F
→
05/26 23:59, , 10F
05/26 23:59, 10F
→
05/27 00:00, , 11F
05/27 00:00, 11F
→
05/27 00:02, , 12F
05/27 00:02, 12F
→
05/27 00:03, , 13F
05/27 00:03, 13F
→
05/27 01:30, , 14F
05/27 01:30, 14F