開發平台(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