作者ric2k1 (Ric)
看板EE_DSnP
标题Re: [问题] hw1.2.p2b
时间Tue Mar 17 21:31:42 2009
※ 引述《lovelylion2 (麻署鼠)》之铭言:
: 这题要用到function object的概念
: 教授在课堂上示范的example,原封不动丢进去compile,会出现以下警告:
: (我用 g++ -g -Wall -o 这些flag )
: fotest.cpp:6: 「class P」 有虚函式却没有虚解构函式
: fotest.cpp:12: 「class A」 有虚函式却没有虚解构函式
: fotest.cpp:18: 「class B」 有虚函式却没有虚解构函式
: 虽然只是警告,不过是什麽意思呢..?
Please add a "virtual destructor to class P". That is:
virtual ~P() {}
: -----
: 另外,题目中用selectionSort(arr, Less())来决定sort的顺序
: 其中Less()是创造一个临时的Less物件(呼叫default constructor,如果有的话)
: 然後传给funtion吗?
: 那,是不是function结束後就会把这个临时的物件释放掉呢?
Yes. 他会自动 destruct.
: 还有还有,selectionSort的prototype用
: void selectionSort(vector<int>& array, const Compare& compare);
: 而不是
: void selectionSort(vector<int>& array, const Compare compare);
: 是为了节省记忆体空间吗?
因为对 selectionSort 而言没有必要 copy 一份 Compare 的 object,
所以用 reference 传入就好, 但因为不希望 function 去改它, 所以加 const.
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 61.224.42.209