Search code examples
c++structfunction-signature

Specifying struct in function signature


Say I have

struct mystruct
{
};

Is there a difference between:

void foo(struct mystruct x){}

and

void foo(mystruct x){}

?


Solution

  • Not in the code you've written. The only difference I know of between using a defined class name with and without struct is the following:

    struct mystruct
    {
    };
    
    void mystruct() {}
    
    void foo(struct mystruct x){} // compiles
    void foo(mystruct x){} // doesn't - for compatibility with C "mystruct" means the function
    

    So, don't define a function with the same name as a class.