You are here:

C++/override keyword with virtual functions


I got lots of libraries in native C++ for MS VisualStudio and want to compile them with g++ on a Linux box.
I fixed some windows/linux issues (backslash in path, CRLF, missing newline at end of incude file etc) and in  Gnu centric forums I usually read something like "We are complying to standards, MS is not"

Now I found you as a rather independent expert to show you this syntax:

class ITest1
     virtual ~ITest1() {};
     virtual const wchar_t* GetDescription() const = 0;

// Test1 - the default implementation of ITest1
class Test1: public ITest1
 std::wstring m_wstrDescription;

     Test1(const wchar_t* wszDescription = NULL);
     virtual const wchar_t* GetDescription() const override ;

This is fine for VisualStudio but g++ complains about the override keyword. (I understand its purpose is to make sure you do not by error invent a new method, but implement something declared in the interface).
Is this really MS specific and I have to remove it?  

Yes. Mostly.

override is part of C++/CLI - the C++ extensions for use with the Common Language Infrastructure (e.g. the .NET managed execution environment) which Microsoft invented and implemented for Visual C++ 2005 and also submitted to ECMA for standardisation (that's the 'mostly' part!). See starters for more information and then maybe look at which mentions override as a C++/CLI keyword.

However Microsoft 'helpfully' allows override, sealed and abstract even in non-managed native code projects as Microsoft extensions to C++ - doh!

To force MSVC++ to not accept C++/CLI code and only (its implementation of) C++ turn off common language runtime support in project properties in Visual Studio. For VS 2005 & 2008 for example this is: Common Language Runtime Support : No Common Language Runtime support on the General project configuration tab. If using the command line and the cl program do _not_ specify /clr.

I do not know for sure how to prevent MSVC++ from accepting override, sealed and abstract in native code projects, as I do not use them so it has never arisen <g>. However I would start by turning off Microsoft language extensions (for recent Visual Studio versions: Project Properties / C++ / Language - Disable Language Extensions : yes,  or /Za from the command line using cl. See for details of the /Za option.

If the libraries you have are intended for native C++ and are written using only standard facilities then all should work once you have ironed out disagreements in how the C++ language should be written between MSVC++ and g++. Hopefully many of these will be picked up when you specify no Microsoft C++ language extensions.

However if any of these libraries use operating system or compiler / library specific features then you will have to go through a more onerous porting phase to get things running under g++ and Linux. Note: if I remember correctly you need Microsoft C++ language extensions enabled if you include windows.h in a source file so disabling language extensions will again give you a clue to some areas where problems may be lurking of this nature.

Finally, if you do not own the rights to any of these libraries then you should read the terms and conditions in any license very carefully to make sure you are allowed to use the code in this way.

Note: I compile under both MSVC++ and g++ frequently. I find that once you have  a little code up and running on one system / compiler it pays to get it up and running on the other system / compiler as soon as possible - otherwise things can get away from you and the task can become much larger when you do try to get things working under the other system / compiler! Unit tests are very useful in this scenario.

So, once you have done the major porting work (including of course creating build scripts for the other platform and compiler - make files or whatever) it pays to make sure any changes and additions compile, build and run correctly on all target platforms as soon as possible.

Hope this is of some use and good luck with your porting efforts.  


All Answers

Answers by Expert:

Ask Experts


Ralph McArdell


I am a software developer with more than 15 years C++ experience and over 25 years experience developing a wide variety of applications for Windows NT/2000/XP, UNIX, Linux and other platforms. I can help with basic to advanced C++, C (although I do not write just-C much if at all these days so maybe ask in the C section about purely C matters), software development and many platform specific and system development problems.


My career started in the mid 1980s working as a batch process operator for the now defunct Inner London Education Authority, working on Prime mini computers. I then moved into the role of Programmer / Analyst, also on the Primes, then into technical support and finally into the micro computing section, using a variety of 16 and 8 bit machines. Following the demise of the ILEA I worked for a small company, now gone, called Hodos. I worked on a part task train simulator using C and the Intel DVI (Digital Video Interactive) - the hardware based predecessor to Indeo. Other projects included a CGI based train simulator (different goals to the first), and various other projects in C and Visual Basic (er, version 1 that is). When Hodos went into receivership I went freelance and finally managed to start working in C++. I initially had contracts working on train simulators (surprise) and multimedia - I worked on many of the Dorling Kindersley CD-ROM titles and wrote the screensaver games for the Wallace and Gromit Cracking Animator CD. My more recent contracts have been more traditionally IT based, working predominately in C++ on MS Windows NT, 2000. XP, Linux and UN*X. These projects have had wide ranging additional skill sets including system analysis and design, databases and SQL in various guises, C#, client server and remoting, cross porting applications between platforms and various client development processes. I have an interest in the development of the C++ core language and libraries and try to keep up with at least some of the papers on the ISO C++ Standard Committee site at


©2016 All rights reserved.