   Address of tempories
  Ive always know that taking the address of a tempory is wrong, but im wondering why i get different results for the following.D3DXMATRIX P;m_FX->SetMatrix(m_hWVP, &(P * P));//error C4238: nonstandard extension used : class rvalue used as lvalue/*HRESULT SetMatrix(  D3DXHANDLE hParameter,  CONST D3DXMATRIX* pMatrix); */struct num{num(int _n) : n(_n){}num operator*(const num& other){num T = *this;return T.n * other.n;}int n;};void write(const num* in){cout << (*in).n << endl;}int _tmain(int argc, _TCHAR* argv[]){num a = 8;num b = 7;write ( &(a * b) );return 0;}//No error or warning
  It's probably because when you compiled the second code you didn't have the warning level set to level 4. MSVC defaults to level 3.   ;  I would guess that the member function SetMatrix doesn't use 'const' for the parameter(and is backed up by a Google search). Your function write does use const and it is this that makes taking the address of the temporary allowed. I am unsure what the standard says with respect to this, but I would guess that it is allowed if you are compiling with Visual C++ 2005/2008. I think it has to do with the fact that the 'lifetime' of a temporary object may be extended when used in a const expression. Or something along those lines.   ;  Hi,Nope, the first example builds with an error, not a warning. Both were compiled on Warning 3, with show warnings as errors turned off.And if i set the second example to level 4 warnings, then it still only shows up as a warning, not an error, like in the first example.Do you think that maybe directx is turning something on in one of their headers to display warnings as errors?Quote:I would guess that the member function SetMatrix doesn't use 'const' for the parameter(and is backed up by a Google search)Could you show me the link you found?, because according to the docs it does.http://msdn.microsoft.com/en-us/library/bb205720(VS.85).aspx   ;  You probably have nonstandard extensions disabled in the first example.   ;Quote:Original post by maya18222Quote:I would guess that the member function SetMatrix doesn't use 'const' for the parameter(and is backed up by a Google search)Could you show me the link you found?, because according to the docs it does.http://msdn.microsoft.com/en-us/library/bb205720(VS.85).aspxHmm. I think that WAS the link I used and it does indeed show that it takes a const. I don't know what I was thinking, sorry.   