Jump to content
  • Advertisement
Sign in to follow this  
Helderash

Use of Undefined Type

This topic is 4322 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello folks! Im currently working on a small 2D Direct-X tile engine, in the hopes of making a simple tic-tac-toe game. I've recently been debugging the code, but theres two errors I just cant seem to sort out, and they're driving me nuts. The errors are: c:\documents and settings\james dobrowski\my documents\visual studio 2005\projects\2d game shell\2d game shell\graphicscore.h(515) : error C2027: use of undefined type 'cTexture' c:\documents and settings\james dobrowski\my documents\visual studio 2005\projects\2d game shell\2d game shell\graphicscore.h(16) : see declaration of 'cTexture' c:\documents and settings\james dobrowski\my documents\visual studio 2005\projects\2d game shell\2d game shell\graphicscore.h(515) : error C2227: left of '->GetTextureCOM' must point to class/struct/union/generic type on the following line of code: if(FAILED(m_pD3DDevice->SetTexture(Num, Texture->GetTextureCOM()))) return false; The function it lies within is as follows: bool cGraphics::SetTexture(short Num, cTexture *Texture) { if(m_pD3DDevice == NULL || Num < 0 || Num > 7) return false; if(Texture == NULL) { if(FAILED(m_pD3DDevice->SetTexture(Num, NULL))) return NULL; }else{ if(FAILED(m_pD3DDevice->SetTexture(Num, Texture->GetTextureCOM()))) return false; } return true; } Texture is a class which is below, defined in the usual way. class cTexture { //Code here. }; At the top of the code, I've added the line "class cTexture;" so it may be used by previously defined code. If anyone could help with this it would be greatly appreciated. Thankyou for everything!

Share this post


Link to post
Share on other sites
Advertisement
Adding "class cTexture" won't help if you want to access it's member functions or variables. For that, you need to include the header file that has the full declaration of cTexture.

Share this post


Link to post
Share on other sites
Aha! I just had the two classes together in the same header file, so i suspected it would be okay. I guess I have some re-organising to do.

Thanks for the help MENTAL!

Share this post


Link to post
Share on other sites
0) Use [code][/code] or [source][/source] tags as appropriate for posting code, please.

1) Some refactoring:


bool cGraphics::SetTexture(short Num, cTexture *Texture) {
if (m_pD3DDevice == NULL || Num < 0 || Num > 7)
return false;
}

void* TexComPtr = Texture == NULL ? NULL : Texture->GetTextureCOM();
return !(FAILED(m_pD3DDevice->SetTexture(Num, TexComPtr)));
}


That is based on the following observations:

- It's poor style to use 'NULL' when you want a boolean return type. It happens to work (NULL is 0, and 0 is false), but is inconsistent, and misleading (NULL is expected to indicate a null pointer). Similarly, don't use NULL to mean a 0-value integer or a 0-value character ('\0' - on ascii tables this is sometimes referred to as NUL, with one L).

- The SetTexture call is effectively the same in both cases; therefore we could just use the if-logic to determine the value for the second parameter.

- But the calculation there is simple enough that we can in turn just use the ternary operator. I did assign that result to a temporary, though, because the overall expression is quite long otherwise. You should change 'void*' to the actual type returned by the GetTextureCOM() call (obviously I don't know what that is).

- Finally, we can get rid of the if-condition entirely, by simply noting that false is returned when FAILED(blah) and true is returned otherwise. The resulting !(FAILED construct is ugly, though; IIRC there's a SUCCESS macro as well or something like that, but I'm not sure of the actual name.

- You might want to do something about the magic numbers bounding 'Num', too.

2) As was indicated, the problem is with the source organization. The *real* problem is that you are trying to put code like this in a header file. Don't do that. Definitions of functions only really work in header files if they are inline (either explicitly marked 'inline' or written within the class body). You should only use that for things that are simple (because you can bloat the code by trying to inline big things) *and* unlikely to change much (because you are effectively welding them into what is supposed to be the interface to your class).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!