C++17 Is it legal to use a typedef'd type in definition bit not declaration?

40 Views Asked by At

This has come up in a code review of more complex code so I'll ask a generic question here :-

Using C++17 here if it matters.

Assume you have a class MyType with some definition. Assume you have something like "

using MyTypePtr = std::shared_ptr<MyType>

In a header file you have a function :-

void myFunc(std::shared_ptr<MyType> ptr);

And then in the implementation in another file you have :-

void myFunc(MyTypePtr ptr)
{
}

Is this legal in C++? The compiler (msvc & gcc) don't complain and it seems to work, but I'm not sure if the One Definition Rule or something similar applies here? Both definitions have the same types but via a different series of tokens? Does that matter in this context?

0

There are 0 best solutions below