How can g ++ mimic the behavior of an instance of an MSVC ++ template?

I am trying to port my own lib from Visual Studio to g ++ on GNU / Linux, and I am having some problems compiling templates. Indeed, in Visual C ++, templates are only generated when they are explicitly used in the code, although it seems (from my mistakes) that g ++ evaluates the contents of the templates before they are first used. This results in the following error:

error: incomplete type ‘X’ used in nested name specifier

... because I am including some classes after the template code, not before. I do this because of conflict between conflicts.

So, Visual C ++ does not try to resolve the template content when used, and g ++ does the resolution as soon as possible.

class MyClass;
template<class _Ty>
void func(MyClass* a_pArg)
{ 
   a_pArg->foo();
};

(_ Ty is not used, but it does not matter, just explain the problem)

Visual ++ ( MyClass ), g++ - , MyClass .

g++ ?

+5
4

, . MSVC , , . MSVC . , , . MSVC . GCC .

, MyClass , . .

+9

, gcc , V++ ( ). , - gcc. ( , ). ,

// provide declarations
class MyClass;

template<class T>
void func(MyClass* a_pArg);

// provide definition of MyClass
class MyClass
{
   // watever
};

// provide definition of func
template<class T>
void func(MyClass* a_pArg);
{ 
   a_pArg->foo();
};
+1

CLang gcc, CLang -fdelayed-template ( ), -fms-extensions, MSVC ( ).

, CLang, MSVC ( ), CLang MFC 2 - 3 , - . MFC (.. V++).

+1

Visual ++ , .

, , Visual Studio 2015 /Za. , , /Za GCC .

0

All Articles