Forum Discussion

🚨 This forum is archived and read-only. To submit a forum post, please visit our new Developer Forum. 🚨
Stobby84's avatar
Stobby84
Honored Guest
11 years ago

Some questions on C++ syntax

Dear all,
I taking the opportunity of this section to ask for a general C++ syntax question.
I am a passionate C++ programmer who is enjoying using Oculus SDK examples to learn how to develop graphics (I'm not a professional, I do it in my spare time as hobby).

Reading lines of OculusRoomTiny demo (I learnt A LOT with it) I've noticed this syntax in function declarations:

Shader(ID3D10Blob* s, int which_type) : numUniformInfo(0)


what does the colon stands for? I know its usage for inherited classes but I've never noticed in function declarations.

Also a second question: I've found a lot of structures which contains a constructor (like Shader) are they classes?

Maybe these are trivial questions.. thanks in advance to all!

3 Replies

  • The stuff after the colon on a function is an initializer list. It lets you more easily initialize members before the function body starts running. It is also the only way to initialize certain variables (i.e. const members). In this case "numUniformInfo" is a variable and it is set to "0".

    Structs and classes are basically the same thing. Struct was popular in C and carried over to C++. The only practical difference is that Struct members are public by default and Class members are private by default. Otherwise they are the same.
  • "Stobby84" wrote:
    I taking the opportunity of this section to ask for a general C++ syntax question.


    You'll probably get more detailed replies if you ask on existing general purpose programming sites, and/or check for existing questions similar to your own. For instance, googling "c++ constructor colon" returns this as the first result: C++, What does the colon after a constructor mean?
  • Thank you very much for your answer.
    I'm using Oculus also to learn something new and really interesting.