Skip to main content
GameDev.net gamedev.net
🔒 Locked

take a look

Started by luasitdown Feb 1, 2006 at 9:53 AM 6 replies 650+ views
Original Post
luasitdown
luasitdown

// not work
Mesh * MeshManager::mesh(const std::string meshName)
{
	if ( (  MeshMapIterator iter = m_meshList.find(meshName)  ) != m_meshList.end() )
	{
		return iter->second;
	}
	else
	{
		return 0;
	}
}

// work

Mesh * MeshManager::mesh(const std::string meshName)
{
	if (    m_meshList.find(meshName)    != m_meshList.end() )
	{
                MeshMapIterator iter =  m_meshList.find(meshName);
		return iter->second;
	}
	else
	{
		return 0;
	}
}
// also work
Mesh * MeshManager::mesh(const std::string meshName)
{
	MeshMapIterator iter;
	if ( (  iter = m_meshList.find(meshName)  ) != m_meshList.end() )
	{
		return iter->second;
	}
	else
	{
		return 0;
	}
}



why?
dbzprogrammer
dbzprogrammer
Is this a compiler or run-time error?
We should do this the Microsoft way: "WAHOOOO!!! IT COMPILES! SHIP IT!"
riltniqaz
riltniqaz
Maybe your compiler won't let you declare a variable within an IF statement's parameter?

Quote:
if ( ( MeshMapIterator iter = m_meshList.find(meshName) ) != m_meshList.end() )
Zakwayda
Zakwayda
I don't know what the scope of a variable declared in an 'if' conditional is, but I've never seen that done before; it might not be legal code. In any case, you should post your exact errors when you run into problems, as it will make it easier for people to help you. Also, you might make your std::string arguments references instead of passing by value.

Your last example is probably the best choice of the ones you posted. Assigning within the conditional is legal, but IMO it doesn't make for the clearest code. I'd do it like this:

Mesh* MeshManager::getMesh(const std::string& meshName){    MeshMapIterator iter = m_meshList.find(meshName);    return (iter == m_meshList.end()) ? 0 : iter->second;}
luasitdown
luasitdown
it is compile error.

it give me 8 compile error.
it said "(" is not correct.
Is empty statement ";" necessary?
undelcaration identity iter
there is a lack of ;
illegal else no match if
.......
Zakwayda
Zakwayda
That wouldn't compile for me either - I can't say for sure, but I don't think that's legal code.
luasitdown
luasitdown
thanks.

take a look
	Mesh * createMesh( const std::string& filename, const std::string& meshName, D3DDevice* device);// Is the code nice style?  is it commended?		MeshManager::singleton().createMesh( filename, meshName ,m_device)->load();// Is this line  also nice? Do I need the tmp variable or other?	return m_meshList[meshName] = new SkinnedMesh(filename, meshName, device);
xEricx
xEricx
I highly doubt that's legal to declare a variable inside ()'s...

#include "stdafx.h"int _tmain(int argc, _TCHAR* argv[]){    if(int Legal = 1)    {    }    (int Illegal = 0);    if((int AlsoIllegal = 1))    {    }    return 0;}

d:\tmp\Test123\Test123.cpp(10) : error C2146: syntax error : missing ')' before identifier 'Illegal'd:\tmp\Test123\Test123.cpp(10) : error C2065: 'Illegal' : undeclared identifierd:\tmp\Test123\Test123.cpp(10) : error C2059: syntax error : ')'d:\tmp\Test123\Test123.cpp(11) : error C2146: syntax error : missing ')' before identifier 'AlsoIllegal'd:\tmp\Test123\Test123.cpp(11) : error C2065: 'AlsoIllegal' : undeclared identifierd:\tmp\Test123\Test123.cpp(11) : error C2059: syntax error : ')'


all you need to do, is remove the ()'s

if(MeshMapIterator iter = m_meshList.find(meshName) != m_meshList.end())


it should work.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.