Sign in to follow this  

Forward Delcarations

This topic is 3046 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

Hi, i know how to declare a basic class/struct but is it possible to somehow have what I have below.
// ===============================================================================
// FORWARD DECLARATIONS:
class CScreenManager::MOBILE;

// ===============================================================================
// FUNCTIONS:
bool test_dustbin_func_eo(CScreenManager::MOBILE *pMobile);
bool test_dustbin_func_so(CScreenManager::MOBILE *pMobile);

Is it possible to forward declare the CScreenManager::MOBILE struct? Im not sure how I would go about it, or whether I need to redesign it. Id rather not include the entire screen header into this header. TY for any help

Share this post


Link to post
Share on other sites
Edit: My original reply was posted before I finished :D

If MOBILE is a class contained in a namespace, yes (http://www.devx.com/tips/Tip/32118) but it seems like it is nested in a class, and in that case no, at least not directly.

Something I've done in this case, which may or may not suit your design needs, is as such:


namespace ScreenBlah
{
class Mobile
{
};

class ScreenManager
{
};
}




Then you can forward declare the Mobile class through the namespace as shown in the link above.

Share this post


Link to post
Share on other sites
never actually made my own namespace, dont know much about it. guess I could take alook at them, same I cant do it directly :(

TY

Share this post


Link to post
Share on other sites
Namespaces are just a convenient way to separate 'logical units' of your program. They are often used to to give a broader sense of structure or unity among their constituents.

Here is a good link to read up on them :)

http://www.cprogramming.com/tutorial/namespaces.html

Edit: Just so you know, if having the classes nested is a must for your design, I believe there is a way to forward declare the nested class using some template voodoo -- but I've only seen this in passing and couldn't explain it. Maybe someone else will able to do that. Personally, I rarely find myself needing a nested class versus wrapping classes together logically in namespaces, but I concede such cases exist.

Share this post


Link to post
Share on other sites
since test_dustbin_func_eo and test_dustbin_func_so operate on a class declared inside of CScreenManager, should you put those functions inside CScreenManager also?

If not, does it make sense to move the class out side the CScreenManager class?

Just a few questions to ask yourself

Share this post


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