Jump to content
  • Advertisement
Sign in to follow this  

Unknown syntax funtion():x,y

This topic is 3910 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 found an interesting piece of code, but the code does not compile. and i dont know what this special syntax means. I dont know the keyword for google, so searching is quite hard.

class CException
    friend class AutomaticGuardUnguard;

        CException(const std::string &Desc);
        std::string getCallStackString();
        static void _pushFunction(const char *FuncName);    
        static void _popFunction();

        std::string     m_ErrorDescription;
        unsigned int    m_StackDepth;
        static unsigned int                  ms_StackDepth;
        static std::vector<const char*>      ms_Vector;

unsigned int CException::ms_StackDepth = 0;
std::vector<const char*> CException::ms_Vector;


//constructor():datamember ???
CException::CException(const string &Desc) : m_ErrorDescription(Desc), m_StackDepth(ms_StackDepth)

The declarition of CException. What does that : m_ErrorDescription(Desc), m_StackDepth(ms_StackDepth) mean? I know that those both are data member, but i dont know what this double point means in that context. The compiler complains about the return type of the ctr. (If i add anything, he complains, that ctrs must not have any return type).
1>c:\documents and settings\ben\desktop\prometha\header\exception.h(39) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\documents and settings\ben\desktop\prometha\header\exception.h(39) : error C2143: syntax error : missing ',' before '&'
1>c:\documents and settings\ben\desktop\prometha\header\exception.h(39) : error C2511: 'CException::CException(const int)' : overloaded member function not found in 'CException'
1>        c:\documents and settings\ben\desktop\prometha\header\exception.h(17) : see declaration of 'CException'

Share this post

Link to post
Share on other sites
: m_ErrorDescription(Desc), m_StackDepth(ms_StackDepth)
That is an initializing list it sets those properties to the values inside the brackets. Its the similiar to having
CException::CException(const string &Desc)
m_ErrorDescription = Desc;
m_StackDepth = ms_StackDepth;

Share this post

Link to post
Share on other sites
okay very good.
and why do i get that error msg from the compiler ?
missing type specifier, i mean, ctr do not have types.

Share this post

Link to post
Share on other sites
Using the constructor initialization list is slightly beneficial compared to setting the variables inside the constructor body. When you set the variables in the constructor body, the variables are first created, and upon this creation they're given a value which you immediately overwrite once the constructor body executes.

When you use the initialization list the variables are created with the given values, saving the step of creating them and then overwriting them.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!