You are here:

C++/error message



hello, Ralph

do you know the meaning of the following error message??

error: expected unqualified-id before ‘using’

i get that error when i type in include "filename.h"
before the using namespace std;

i couldnt find any errors in my filename.h file, so i dont
know what that error means

any suggestions would help


ps: im using g++ compiler in ubuntu

Sorry but without seeing a minimal example that produces the problem I cannot say for sure - human language descriptions are _not_ exact enough.

The error refers to the compiler expecting an unqualified name. This might be because you provided a qualified name when an unqualified name was required or it could be that you have messed up your code and the compiler has got confused as to what is going on. It may even be that the compiler has found a name it does understand - so maybe you are missing additional include files. (note: if filename.h requires other header files included before it then they should most likely be #included in filename.h).

For reference a qualified name is one that specifies the full namespace and type e.g. MyNamespace::MyClass::myStaticMember. An unqualified name is just a name with no :: in it, e.g. myStaticMember.

One area where over-qualification can occur is with the use of enums. In C and C++ the enum type name does not form a name space, unlike namespaces, classes and structs. Thus it should not be used when specifying enumeration values, viz:

    enum Colours { black, grey, red, green, blue, white };
    // ...
    Colours correct = black;          // OK
    Colours wrong = Colours::black;    // BAD. NOT C or C++

One problem with qualifying enumeration values is that the Microsoft Visual C++ compiler has accepted such non-standard qualifications for a long time and as far as I know still accepts them by default (you have to turn off Microsoft language extensions for it not to be accepted). So any code originally written using Microsoft Visual C++ can break for this reason when compiled using more compliant compilers.

Another area that may cause you problems with qualified names has to do with friends and class templates.

From what you say it would seem to be a problem with the filename.h file, even though you think this is not the case. What you think is correct C++ and what the compiler does are probably quite different things - and right or wrong it is the compiler you have to please!

So we have to locate exactly what it is the compiler is complaining about before anything else. First try commenting out the #include line and see if the specific error you mention here error goes away. Of course you will expect to get other errors because filename.h is no longer included, but those are incidental, and should be further into your source file.

If doing this fixes the problem then re-instate the #include "filename.h" line (i.e. uncomment it) and check the end of the filename.h file for possible errors, working your way up the file.

If it does not then you will have to look at other factors - and again I cannot help as you have given no information of other code you have.

If all else fails use a binary chop method of commenting out code in filename.h (or other source files) to home in on the part(s) that have confused the compiler. That is start with approximately the final half of the code commented out. Ensure that you leave enough uncommented at the end to close open sections of code correctly - closing curly braces and the like - if necessary.

If the code compiles with the final half mostly commented out then uncomment the top half of the previously commented out section (i.e. the initial three quarters of the code is now uncommented). If the code does not compile with the latter portion of the code commented out, comment out additionally half of the uncommented code (i.e. so the latter three quarters of the code is now commented out) and re-compile. Repeat, commenting or uncommenting more of the code until you have homed in on the line(s) of code the compiler is complaining about.

Note that you have to be careful to ensure the code is consistent each time you comment or uncomment code, otherwise you will get additional errors introduced.

You can of course use variations on the theme. In general the idea is to reduce what the compiler has to compile until it is obvious exactly what it is that is causing the problem.

For header files you can try just creating a implementation file that only includes that file and compiling this implementation file. Or you can try compiling the header file directly - but you may need to tell the compiler what language to use when doing so, check the g++ documentation (the g++/gcc man page is a good place to start - ensure you have it installed).

Hope this helps you locate the area of code causing the problem if nothing else. As I have said, without seeing a reduced example of the problem code I cannot give you a firm answer. And as soon as you have produced such a short example you will of course have located the problem code yourself and most likely have been able to fix it!  


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


©2017 All rights reserved.