简体   繁体   中英

VS2010 Compiler define

In gcc I am writting friend class FriendMaker<T>::Type but Visual Studio wants friend FriendMaker<T>::Type . So I think it is time to go compiler specific.

So What I need to ifdef for Visual Studio ? I am using 2010 at the moment but I may switch to 2012 latter.

Use the macro _MSC_VER . To check if the compiler is VS2010, or above:

#if _MSC_VER >= 1600

The following are values for the different versions of VS:

  • VS 2003 (VC7.1): 1310
  • VS 2005 (VC8): 1400
  • VS 2008 (VC9): 1500
  • VS 2010 (VC10): 1600
  • VS 2012 (VC11): 1700

Just use the friend class ... syntax for both compilers. The friend ... syntax, without the class keyword, is actually invalid; VS2010 is incorrect in not complaining about it.

See this question .

I think you need to use following code for cross compiler:

template <typename T> class B;

template <typename T>
class A
{
    friend typename B<T>::V;
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM