08/02/13 10:57:14
C++の一時オブジェクトについて質問します。gcc 3.2.1です。
下記のようなコードで"taking address of temporary"のWARNINGが出ますが、
この場合は無視しちゃってもいいですか?いいですよね?
#include <stdio.h>
class CTmp
{
public:
int x,y;
CTmp(int a,int b):x(a),y(b){};
};
int Foo(CTmp* pTmp)
{
if(pTmp) return pTmp->x + pTmp->y;
return 0;
}
int main(int argc,char** argv)
{
int result=Foo(&CTmp(1,2));
printf("%d\n",result);
return 0;
}