MS VisC++ 2010 express: Suddenly Project no longer sees header files - c++

This may be hard to explain. I have been developing a program for about a month now in MS VisC++ 2010 express. I have had no strange problems and was ready to build my project for the 100th time when suddenly, many of the .cpp files seemed to loose contact with the .h files. For instance, in the main function, objects that I had created and used weeks ago, suddenly got the red line under them and the syntax error "theClass is undefined". This applies to iostream, so suddenly cout is undefined. I have no idea what happened. One second to another all external header files and libraries suddenly disappeared in the eyes of the IDE. In the .cpp files, when I declare the class constructor
//initializes a poker game
aPokerGame::aPokerGame(void)
{
stopPlaying = 'n';
}
I get the line under the class name aPokerGame and this error is "must be a class or a namespace name". Isn't this what would be happen if the .h files disappeared? In fact, not all .cpp files are having this problem, only some. Others have really weird errors in them like "no default constructor exists for class"std::basic_ostream<wchar...". All these errors appeared at once.
The header files seem fine. Though one of them has "Error: expected a declaration" under the "Private:" heading for the private members.
Please help!
Here is a sample of the compile errors:
1>------ Build started: Project: firstProj, Configuration: Debug Win32
------ 1> userPlayer.cpp 1>c:\users\bn\dropbox\myprojects\mysoftware\c++\firstproj\firstproj\userplayer.h(9):
error C2504: 'Player' : base class undefined 1>c:\program files
(x86)\microsoft visual studio 10.0\vc\include\iostream(10): error
C2059: syntax error : 'namespace' 1>c:\program files (x86)\microsoft
visual studio 10.0\vc\include\iostream(10): error C2334: unexpected
token(s) preceding '{'; skipping apparent function body
1>c:\users\bn\dropbox\myprojects\mysoftware\c++\firstproj\firstproj\userplayer.cpp(8):
error C3254: 'Player' : class contains explicit override '{ctor}' but
does not derive from an interface that contains the function
declaration
1>c:\users\bn\dropbox\myprojects\mysoftware\c++\firstproj\firstproj\userplayer.cpp(8):
error C2838: '{ctor}' : illegal qualified name in member declaration
1>c:\users\bn\dropbox\myprojects\mysoftware\c++\firstproj\firstproj\userplayer.cpp(8):
error C2535: 'Player::Player(void)' : member function already defined
or declared 1>
c:\users\bn\dropbox\myprojects\mysoftware\c++\firstproj\firstproj\player.h(18)
: see declaration of 'Player::Player'
1>c:\users\bn\dropbox\myprojects\mysoftware\c++\firstproj\firstproj\userplayer.cpp(13):
error C3254: 'Player' : class contains explicit override '{dtor}' but
does not derive from an interface that contains the function
declaration
1>c:\users\bn\dropbox\myprojects\mysoftware\c++\firstproj\firstproj\userplayer.cpp(13):
error C2838: '{dtor}' : illegal qualified name in member declaration
1>c:\users\bn\dropbox\myprojects\mysoftware\c++\firstproj\firstproj\userplayer.cpp(13):
error C2535: 'Player::~Player(void)' : member function already defined
or declared 1>
c:\users\bn\dropbox\myprojects\mysoftware\c++\firstproj\firstproj\player.h(19)
: see declaration of 'Player::~Player'
1>c:\users\bn\dropbox\myprojects\mysoftware\c++\firstproj\firstproj\userplayer.cpp(18):
error C3254: 'Player' : class contains explicit override 'userBets'
but does not derive from an interface that contains the function
declaration
1>c:\users\bn\dropbox\myprojects\mysoftware\c++\firstproj\firstproj\userplayer.cpp(18):
error C2838: 'userBets' : illegal qualified name in member declaration
1>c:\users\bn\dropbox\myprojects\mysoftware\c++\firstproj\firstproj\userplayer.cpp(38):
fatal error C1075: end of file found before the left brace '{' at
'c:\users\bn\dropbox\myprojects\mysoftware\c++\firstproj\firstproj\player.h(12)'
was matched 1> pokerRound.cpp
1>c:\users\bn\dropbox\myprojects\mysoftware\c++\firstproj\firstproj\npcplayer.h(9):
error C2504: 'Player' : base class undefined
1>c:\users\bn\dropbox\myprojects\mysoftware\c++\firstproj\firstproj\userplayer.h(9):
error C2504: 'Player' : base class undefined 1>c:\program files
(x86)\microsoft visual studio 10.0\vc\include\iostream(10): error
C2059: syntax error : 'namespace' 1>c:\program files (x86)\microsoft
visual studio 10.0\vc\include\iostream(10): error C2334: unexpected
token(s) preceding '{'; skipping apparent function body 1>c:\program
files (x86)\microsoft visual studio 10.0\vc\include\time.h(35): error
C2059: syntax error : 'string' 1>c:\program files (x86)\microsoft
visual studio 10.0\vc\include\time.h(35): error C2334: unexpected
token(s) preceding '{'; skipping apparent function body
1>c:\users\bn\dropbox\myprojects\mysoftware\c++\firstproj\firstproj\pokerround.cpp(16):
error C2059: syntax error : 'namespace'

Probably you are missing a semicolon after a class definition or something like that in a header file which you #include into a bunch of other files above some standard header files, which makes everything mess up and the compiler report things as errors that are only errors because you forgot one little thing way up the line.
Double check the syntax of each of your header files meticulously, looking for mismatching parentheses or braces, and making sure you have semicolons where they are needed.

Related

syntax error in VC xtree internal header with Qt/boost project

I'm using Boost with a Qt project.
I added these lines to my .pro file.
INCLUDEPATH += C:/local/boost_1_62_0/
LIBS += "-LC:/local/boost_1_62_0/lib64-msvc-12.0/"
I'm linking against boost, as I use a the libICP library, that includes boost/multi_array and boost/array.
When I compile, I get a lot of errors :
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xtree:20: error: C2143: syntax error : missing ',' before '<'
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xtree:21: error: C2518: keyword 'typename' illegal in base class list; ignored
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xtree:22: error: C2518: keyword 'typename' illegal in base class list; ignored
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xtree:132: error: C2065: '_Iterator_base0' : undeclared identifier
I suspect xtree is used by the implementation of multi_array or array, but I don't really know where to go from here.
Ok, so I found the solution (I was working on this issue since yesterday...)
In case someone else has a similar issue, it was just a case of unbalanced } at the end of the file ICP_Registration.h, that includes libICP.

Boost foreach conflicts with Q_FOREACH (Qt) and moc generation?

I have a program edited in Vs 2008 using some libraries such as Qt and Point Cloud Library (PCL).
PCL has a 3rd party library which contains boost.
However, some errors appeared after compiling:
1>C:\Program Files\PCL
1.5.1\3rdParty\Boost\include\boost/multi_index/sequenced_index.hpp(926)
: error C3083: 'Q_FOREACH': the symbol to the left of a '::' must be a
type 1>C:\Program Files\PCL
1.5.1\3rdParty\Boost\include\boost/multi_index/sequenced_index.hpp(926)
: error C2039: 'tag' : is not a member of 'boost' 1>C:\Program
Files\PCL
1.5.1\3rdParty\Boost\include\boost/multi_index/sequenced_index.hpp(926)
: error C2061: syntax error : identifier 'tag' 1>C:\Program Files\PCL
1.5.1\3rdParty\Boost\include\boost/multi_index/ordered_index.hpp(1399) : error C3083: 'Q_FOREACH': the symbol to the left of a '::' must be a
type 1>C:\Program Files\PCL
1.5.1\3rdParty\Boost\include\boost/multi_index/ordered_index.hpp(1399) : error C2039: 'tag' : is not a member of 'boost' 1>C:\Program
Files\PCL
1.5.1\3rdParty\Boost\include\boost/multi_index/ordered_index.hpp(1399) : error C2061: syntax error : identifier 'tag' 1>C:\Program Files\PCL
1.5.1\3rdParty\Boost\include\boost/multi_index/hashed_index.hpp(1254) : error C3083: 'Q_FOREACH': the symbol to the left of a '::' must be a
type 1>C:\Program Files\PCL
1.5.1\3rdParty\Boost\include\boost/multi_index/hashed_index.hpp(1254) : error C2039: 'tag' : is not a member of 'boost' 1>C:\Program
Files\PCL
1.5.1\3rdParty\Boost\include\boost/multi_index/hashed_index.hpp(1254) : error C2061: syntax error : identifier 'tag' 1>C:\Program Files\PCL
1.5.1\3rdParty\Boost\include\boost/multi_index/random_access_index.hpp(1012)
: error C3083: 'Q_FOREACH': the symbol to the left of a '::' must be a
type 1>C:\Program Files\PCL
1.5.1\3rdParty\Boost\include\boost/multi_index/random_access_index.hpp(1012)
: error C2039: 'tag' : is not a member of 'boost' 1>C:\Program
Files\PCL
1.5.1\3rdParty\Boost\include\boost/multi_index/random_access_index.hpp(1012)
: error C2061: syntax error : identifier 'tag'
For the first problem, the error location in the source file is:
template<typename SuperMeta,typename TagList>
inline boost::mpl::true_* boost_foreach_is_noncopyable(
boost::multi_index::detail::random_access_index<SuperMeta,TagList>*&,
boost::foreach::tag) // <-------------error here for the first compile error.
{
return 0;
}
I think maybe this indicates that the Q_FOREACH conflicts with the boost foreach.
But I do not know how to solve this problem?
The problem is that Qt defines a foreach macro (#define foreach Q_FOREACH) which conflicts with the boost::foreach namespace.
The easiest ways to solve it is to either include Boost before Qt or simply undefine the Qt's macro before including the boost's header file. I prefer the second since it won't need extra documentation (// remember to include Boost before Qt), and it is easier to manage in nested header files and if you use precompiled headers.
#undef foreach
#include <boost/foreach.hpp>
This option is less invasive than disabling Qt's keywords (compilation flag -DQT_NO_KEYWORDS) and can be applied only in the affected files if wanted. It won't affect the use of Q_FOREACH (obviously if you use the Qt's foreach it will fail). It also works independently that Qt is included before or after <boost/foreach.hpp>.
Setting compiler flag -DQT_NO_KEYWORDS, disables the clash between boost and qt!
But then you need to replace the qt keywords in your code like slots, signals, emit ..., see this post.
(I got this message when introducing boost::multi_index container in my project.)
(For qmake projects CONFIG += no_keywords does this.)
(For cmake project add_definitions(-DQT_NO_KEYWORDS) does this.)

Why do I get errors when I #include curl.h?

I'm trying to get libcurl to work with my C++ project.
I've added libcurl to my project.
I've also added the header files, preprocessor and linker configuration.
When adding #include to my project I get a lot of winnt.h errors:
c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winnt.h(1084): error C2988: unrecognizable template declaration/definition
1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winnt.h(1084): error C2059: syntax error : '('
1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winnt.h(1084): error C2090: function returns array
...
What is the reason to this problem?
Thanks.

Dependencies, Namespace, and Headers

I believe have dug myself into a hole. While breaking up my single file, couple thousand line chunk of code into multiple files I appear to have grossly screwed up the structure of the program.
I'm new to C++ and its header files and namespace management so I've been learning as I go.
I guess I don't fully understand how #include, using, and namespaces interrelate and what transfers over to other files, etc.
Reading through MSDN documentation I can see bits and pieces of my problem but the solution eludes me.
As of now I have four .cpp files and headers:
1) A Main File
2) A GameData .cpp and its header that is contained in the namespace pData
3) A GameSettings .cpp and its header that is contained in the namespace pSettings
4) A GeneralScreens .cpp and its header that is contained in the namespace pScreens
Upon compile the debugger spews over 100 of error like:
>c:\program files (x86)\microsoft visual studio 10.0\vc\include\utility(454): error C2447: '{' : missing function header (old-style formal list?)
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\utility(463): error C2039: 'pair' : is not a member of 'std'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\utility(463): error C2955: 'pScreens::std::pair' : use of class template requires template argument list
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\utility(173) : see declaration of 'pScreens::std::pair'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cwchar(33): error C2873: 'wcsrtombs' : symbol cannot be used in a using-declaration
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cwchar(41): error C2039: 'wctob' : is not a member of '`global namespace''
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cwchar(41): error C2873: 'wctob' : symbol cannot be used in a using-declaration
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cwchar(42): error C2039: 'wmemchr' : is not a member of '`global namespace''
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cwchar(42): error C2873: 'wmemchr' : symbol cannot be used in a using-declaration
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cwchar(42): error C2039: 'wmemcmp' : is not a member of '`global namespace''
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cwchar(42): error C2873: 'wmemcmp' : symbol cannot be used in a using-declaration
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cwchar(42): error C2039: 'wmemcpy' : is not a member of '`global namespace''
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cwchar(42): error C2873: 'wmemcpy' : symbol cannot be used in a using-declaration
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cwchar(43): error C2039: 'wmemmove' : is not a member of '`global namespace''
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\new(93): error C2039: 'nothrow_t' : is not a member of 'std'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\new(93): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\new(93): error C2143: syntax error : missing ',' before '&'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\new(99): error C2039: 'new_handler' : is not a member of 'std'
Are these errors indicative of something?
I'm assuming something is wrong with the way I'm referencing the std library though I have no idea how to pinpoint the error because all the errors are in library files.
Most likely you're missing a semicolon on the end if a class or struct definition in a header file. The compiler then treats every identifier it sees as an instance of that class instead of what you're expecting. Then the compiler complains because it has no idea what to do with the stray {}s it sees.
Check the header that's #included just before <utility> in your implementation file; that header is most likely where the fault lies.
Side note: To avoid this problem, always #include standard headers before your own headers in a .CPP file. For example, instead of
// MyGameThing.cpp
#include "MyGameThing.hpp"
#include <utility>
#include <string>
// code
do
// MyGameThing.cpp
#include <utility>
#include <string>
#include "MyGameThing.hpp"
// code
That way you won't get compile errors like this buried in the standard headers.
The first compiler error is going to be your best clue:
c:\program files (x86)\microsoft visual studio 10.0\vc\include\utility(454): error C2447: '{' : missing function header (old-style formal list?)
I'm guessing that what's happening here is you may have a class or struct declaration with no ending semicolon. So you have something like this:
struct Foo
{
} // <--- no semicolon here will generate funky errors
But overall, pay close & special attention to the first compiler error.
As #Billy mentions in the comments below, the rules for struct and class are the same. In either case, you need the semicolon. Also, old-school C code will often typedef structs like this:
typedef struct tag_Foo
{
} Foo; // <-- still need the semicolon
Here, you still need the semicolon.
If using Visual C++, open the first cpp file and press CTRL+F7, this will compile only the cpp file, check the first error and try to correct this. When fixed go to the next cpp file if the error persists.
Billy's attempt is a decent one, but the usual response to a missing ';' is for the compiler to say so. A missing '}' on the other hand can seriously confuse standard headers included afterward because all their content is within the scope of either the namespace or class that should have been closed. Also, ';' missing is more immediately detectable while a missing '}' isn't necessarily an error so the compiler just pisses a fit at the first thing that doesn't make sense in that scope.
Furthermore, at line 454 in utility for the 2010 compiler is the opening brace for a specialization of tuple_size for std::pair. Post preprocessor that definition would look like so:
template < ... >
struct tuple_size< ::std::pair<_Ty1, _Ty2> >
If you have forgotten a '}' closing a namespace then that's not where pair<> exists anymore. Instead, since it's declared like so:
namespace std { template < ... > struct pair ... }
Whatever scope wasn't closed is now where std is being declared and struct tuple_size< ::std::pair<...> > doesn't make any sense to the parser. Since it's not a valid name it tends to pretend it's not even there and then '{' at the global scope without anything of sense before it is pretty f'n confusing.
BTW, an often unspoken benefit of making minimal examples that cause the problem is that you end up FINDING the problem trying to make it happen.

Error building legacy code with VS 2005

Trying to build a legacy code in VS2005 and get errors in VC header files.
d:\Compilers\Microsoft Visual Studio 8\VC\include\xutility(2096) : error C2065: '_Sb' : undeclared identifier
d:\Compilers\Microsoft Visual Studio 8\VC\include\xutility(2176) : see reference to class template instantiation 'std::istreambuf_iterator<_Elem,_Traits>' being compiled
d:\Compilers\Microsoft Visual Studio 8\VC\include\xutility(2096) : error C3861: '_Strbuf': identifier not found
d:\Compilers\Microsoft Visual Studio 8\VC\include\xutility(2096) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
d:\Compilers\Microsoft Visual Studio 8\VC\include\xutility(2096) : error C2061: syntax error : identifier '_Sb'
d:\Compilers\Microsoft Visual Studio 8\VC\include\xutility(2097) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
d:\Compilers\Microsoft Visual Studio 8\VC\include\xutility(2098) : error C2143: syntax error : missing ';' before '{'
d:\Compilers\Microsoft Visual Studio 8\VC\include\xutility(2098) : error C2334: unexpected token(s) preceding '{'; skipping apparent function body
d:\Compilers\Microsoft Visual Studio 8\VC\include\xutility(2176) : fatal error C1075: end of file found before the left brace '{' at 'd:\Compilers\Microsoft Visual Studio 8\VC\include\xutility(15)' was matched
I find the legacy code uses a vector and if I comment out those variables then the code compiles without any errors.
I get these errors even if I just include vector header without defining any variable.
All the files in the project are cpp files.
Do I need to add some preprocessor directives or compiler settings to get this working?
You may find that running the pre-process phase on one of the files might show if any macros are being expanded that conflict with vector or _Strbuf. See my post on how to do this:
Compiling a project (VS 2008) with the /p argument (preprocess to a file) doesn't compile
You probably need to remove some conflicting predefined macros. Leading underscores followed by uppercase letters, as in _Sb are reserved for the implementation. If you have that defined as something else, you'll get such errors. It's also possible the errors are because you've defined _Strbuf ot _Got.