I have a problem: My codes work well in CentOS g++, but when I compile them in visual studio 2008, the visual studio tells me errors like below:
1.c:\program files (x86)\microsoft visual studio 9.0\vc\include\codeanalysis\sourceannotations.h(19) : error C2144: syntax error : '__w64 unsigned int' should be preceded by '}'
2.error C2143: syntax error : missing '}' before 'namespace'.
My file coding is UTF-8. Should I change them in Unicode all, I change some error file in Unicode,it still has errors like above.
below are some sourecode:
#ifndef ENRC_CODE_DEFS_H
#define ENRC_CODE_DEFS_H
enum ENReturnCode
{
ENRC_SUCCESS = 0,
ENRC_FAILED,
ENRC_NODATA,
ENRC_CONFIG_NOT_AVAILABLE,
ENRC_INVALID_SUBSCRIBE_ID,
ENRC_INVALID_SUBSCRIBE_CONDITION,
ENRC_INVALID_SUBSCRIBER,
ENRC_INVALID_PARAMETER,
ENRC_THREAD_RUNNING,
ENRC_SUBSCRIBE_LIST_EMPTY,
ENRC_OUT_OF_MEMORY // 10
}
e:\my_code\cppcommon\include\errordefs.h(5) : error C2143: syntax error : missing ';' before 'enum [tag]'
next:
#ifndef EN_SMS_SRC_TAO2CPP_H_
#define EN_SMS_SRC_TAO2CPP_H_
#include "SystemMonitorMasterServiceC.h"
#include "SystemMonitorSlaveServiceC.h"
#include "CommonDefs.h"
#include "SystemMonitorServiceDataDefs.h"
namespace EN
{
namespace SMS
{
template < typename _Ty, typename _Cy>
inline
void Tao2Cpp_Enum(_Ty taoValue, _Cy &cppValue)
{
cppValue = (_Cy)taoValue;
}
error C2143: syntax error : missing '}' before 'namespace'
A lot of errors like above.
Thanks. I waste some time to make it easy to read.
You need a semi-colon in the enum declaration:
enum ENReturnCode
{
...
};
Related
I have the following code:
#include "wx\wx.h"
class BClient : public wxApp
{
virtual bool OnInit();
virtual int OnQuit();
};
IMPLEMENT_APP(BClient)
bool BClient::OnInit()
{
return true;
}
int BClient::OnQuit()
{
return 0;
}
As soon I try to add the line
#include <thread>
I receive this errors:
Error 10 error C2347: '__w64' : can not be used with type '__w64
unsigned __int64'
Error 12 error C2143: syntax error : missing ';' before ','
Error 13 error C2059: syntax error : ','
The errors refer to this file: c:\program files (x86)\microsoft visual studio 12.0\vc\include\concrt.h
So, for some reason, wxwidgets and std::thread doesn't mix together.
Can someone explain to me why this is happening and is there a workaround for this issue ?
Thanks.
Something is wrong with your MSVS installation. Here, adding #include <thread> line either before or after #include <wx/wx.h> one works without any problems.
Also, on a completely unrelated note, there is no OnQuit() in the base class, only OnExit().
I keep receiving a long string of errors when I try to declare a vector in the header. I've looked around for awhile, but can't find a solution.
Here are the errors:
1>Compiling... 1>game.cpp 1>c:\users\legacyblade\documents\visual
studio 2008\projects\fourswords\fourswords\input.h(38) : error C2143:
syntax error : missing ';' before '<'
1>c:\users\legacyblade\documents\visual studio
2008\projects\fourswords\fourswords\input.h(38) : error C2071:
'input::vector' : illegal storage class
1>c:\users\legacyblade\documents\visual studio
2008\projects\fourswords\fourswords\input.h(38) : error C4430: missing
type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\legacyblade\documents\visual studio
2008\projects\fourswords\fourswords\input.h(38) : error C2238:
unexpected token(s) preceding ';' 1>main.cpp
1>c:\users\legacyblade\documents\visual studio
2008\projects\fourswords\fourswords\input.h(38) : error C2143: syntax
error : missing ';' before '<' 1>c:\users\legacyblade\documents\visual
studio 2008\projects\fourswords\fourswords\input.h(38) : error C2071:
'input::vector' : illegal storage class
1>c:\users\legacyblade\documents\visual studio
2008\projects\fourswords\fourswords\input.h(38) : error C4430: missing
type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\legacyblade\documents\visual studio
2008\projects\fourswords\fourswords\input.h(38) : error C2238:
unexpected token(s) preceding ';' 1>input.cpp
1>c:\users\legacyblade\documents\visual studio
2008\projects\fourswords\fourswords\input.h(38) : error C2143: syntax
error : missing ';' before '<' 1>c:\users\legacyblade\documents\visual
studio 2008\projects\fourswords\fourswords\input.h(38) : error C2071:
'input::vector' : illegal storage class
1>c:\users\legacyblade\documents\visual studio
2008\projects\fourswords\fourswords\input.h(38) : error C4430: missing
type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\legacyblade\documents\visual studio
2008\projects\fourswords\fourswords\input.h(38) : error C2238:
unexpected token(s) preceding ';'
Here is the source code:
#include <vector>
#include <SFML/Graphics.hpp>
#ifndef _input_h
#define _input_h
class input
{
public:
input();
void update();
//----input keys----//
// Directions
bool upPress;
bool downPress;
bool leftPress;
bool rightPress;
// Actions
bool aPress;
bool bPress;
bool jumpPress;
bool shieldPress;
// Menu
bool startPress;
bool screenshotPress;
bool fullscreenPress;
//------------------//
private:
extern vector<sf::Keyboard::Key> keyBindings;
};
#endif
It gives me the same error with and without extern, and even if I change the type of thing inside the vector (even int).
Thank you so much for reading. It would be great if anyone could help. I need vectors to do what I'm wanting to do. Don't know why it's giving me such trouble. Any other type of variable in the same spot DOES NOT cause the error. Only vectors.
Just to add to what's been said, you need the namespace in the declaration because we usually don't want to bloat up header files with "using namespace std". So if you've seen vectors used elsewhere without std:: in front of it, the namespace was probably declared elsewhere.
You need to use the namespace for vector. Prefix vector with std::.
Also, extern on a class member semantically doesn't make any sense. Remove it.
std::vector<sf::Keyboard::Key> keyBindings;
extern vector<sf::Keyboard::Key> keyBindings;
should be
std::vector<sf::Keyboard::Key> keyBindings;
As the title says, I'm getting a compiler error in a VS2008 C++ program. I'm not sure how better to describe my problem than in code. The following compiles unless I uncomment the TEST line.
#include <windows.h>
#include <iostream>
using namespace std;
//#define TEST //<-- uncomment for error
#ifdef TEST
void test(void* interface)
{
return;
}
#endif
int main()
{
cout << "Hello World" << endl;
system("PAUSE");
return(0);
}
When uncommented I get the following errors:
1>main.cpp(7) : error C2332: 'struct' : missing tag name
1>main.cpp(7) : error C2144: syntax error : '<unnamed-tag>' should be preceded by ')'
1>main.cpp(7) : error C2144: syntax error : '<unnamed-tag>' should be preceded by ';'
1>main.cpp(7) : error C2059: syntax error : ')'
1>main.cpp(8) : warning C4094: untagged 'struct' declared no symbols
1>main.cpp(8) : error C2143: syntax error : missing ';' before '{'
1>main.cpp(8) : error C2447: '{' : missing function header (old-style formal list?)
This is unmanaged code, so I'm not sure what the issue with the word interface is. Is there any way to get this code to compile as is, or do I have to change every instance of the term interface to something else?
Thanks!
If your code needs to include Windows.h then you should avoid using the name interface as it's reserved for the use that the Windows SDK has reserved for it (essentially it's a synonym for the keyword struct). There are probably hacks to work around that problem (you could #undef interface after including the SDK headers), but you should probably avoid using that identifier.
The word interface is reserved by MSVC++, as it is a non-standard keyword added by Microsoft Compiler, which is used to define interface in MSVC++.
So use a different name for the parameter, something like this:
#ifdef TEST
void test(void* test_interface)
{
return;
}
#endif
I have this code from programming pearls
#include <iostream>
//#include <string>
using namespace std;
template <class T>
void measure(char *text)
{
cout<<"measure"<<text<<"\t";
cout<<sizeof(t)<<"\n";
}
#define MEASURE(T,text){
cout<<text<<"\t";
cout<<sizeof(T)<<"\t";
int lastp=0;
for (int i=0;i<11;i++){
T *p=new T;
int thisp=(int)p;
if (lastp!=0)
cout<<" "<<thisp-lastp;
lastp=thisp;
}
cout<<"n":
}
int main(){
return 0;
}
but there are some mistakes
1>------ Build started: Project: new_practises, Configuration: Debug Win32 ------
1> practises.cpp
1>c:\users\david\documents\visual studio 2010\projects\new_practises\practises.cpp(11): error C2143: syntax error : missing ';' before '<<'
1>c:\users\david\documents\visual studio 2010\projects\new_practises\practises.cpp(11): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\david\documents\visual studio 2010\projects\new_practises\practises.cpp(12): error C2143: syntax error : missing ';' before '<<'
1>c:\users\david\documents\visual studio 2010\projects\new_practises\practises.cpp(12): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\david\documents\visual studio 2010\projects\new_practises\practises.cpp(12): error C2086: 'int cout' : redefinition
1> c:\users\david\documents\visual studio 2010\projects\new_practises\practises.cpp(11) : see declaration of 'cout'
1>c:\users\david\documents\visual studio 2010\projects\new_practises\practises.cpp(14): error C2059: syntax error : 'for'
1>c:\users\david\documents\visual studio 2010\projects\new_practises\practises.cpp(14): error C2143: syntax error : missing ')' before ';'
1>c:\users\david\documents\visual studio 2010\projects\new_practises\practises.cpp(14): error C2143: syntax error : missing ';' before '<'
1>c:\users\david\documents\visual studio 2010\projects\new_practises\practises.cpp(14): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\david\documents\visual studio 2010\projects\new_practises\practises.cpp(14): error C2143: syntax error : missing ';' before '++'
1>c:\users\david\documents\visual studio 2010\projects\new_practises\practises.cpp(14): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\david\documents\visual studio 2010\projects\new_practises\practises.cpp(14): error C2086: 'int i' : redefinition
1> c:\users\david\documents\visual studio 2010\projects\new_practises\practises.cpp(14) : see declaration of 'i'
1>c:\users\david\documents\visual studio 2010\projects\new_practises\practises.cpp(14): error C2059: syntax error : ')'
1>c:\users\david\documents\visual studio 2010\projects\new_practises\practises.cpp(14): error C2143: syntax error : missing ';' before '{'
1>c:\users\david\documents\visual studio 2010\projects\new_practises\practises.cpp(14): error C2447: '{' : missing function header (old-style formal list?)
1>c:\users\david\documents\visual studio 2010\projects\new_practises\practises.cpp(21): error C2143: syntax error : missing ';' before '<<'
1>c:\users\david\documents\visual studio 2010\projects\new_practises\practises.cpp(21): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\david\documents\visual studio 2010\projects\new_practises\practises.cpp(21): error C2086: 'int cout' : redefinition
1> c:\users\david\documents\visual studio 2010\projects\new_practises\practises.cpp(11) : see declaration of 'cout'
1>c:\users\david\documents\visual studio 2010\projects\new_practises\practises.cpp(22): error C2059: syntax error : '}'
1>c:\users\david\documents\visual studio 2010\projects\new_practises\practises.cpp(22): error C2143: syntax error : missing ';' before '}'
1>c:\users\david\documents\visual studio 2010\projects\new_practises\practises.cpp(22): error C2059: syntax error : '}'
1>c:\users\david\documents\visual studio 2010\projects\new_practises\practises.cpp(24): error C2143: syntax error : missing ';' before '{'
1>c:\users\david\documents\visual studio 2010\projects\new_practises\practises.cpp(24): error C2447: '{' : missing function header (old-style formal list?)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
What do I need to fix?
DeadMG is correct, there are quite a few mistakes here. The most prominent one is that you are not using #define correctly. It requires that all of the code of the function goes on one line.
#define func(A, B) {//function body goes here}
To allow multi-line #defines, use \s at the end of the lines:
#define MEASURE(T,text) {\
cout<<text<<"\t";\
cout<<sizeof(T)<<"\t";\
int lastp=0;\
for (int i=0;i<11;i++){\
T *p=new T;\
int thisp=(int)p;\
if (lastp!=0) cout<<" "<<thisp-lastp;\
lastp=thisp;\
}\
cout<<"n";\
}
(Note I have fixed a few typos here, including one : where a ; should be.)
The other big problem with your code is in the measure function:
void measure(char *text)
{
cout<<"measure"<<text<<"\t";
cout<<sizeof(t)<<"\n";
}
What is t? I assume you mean text, not t.
The following should compile okay.
#include <iostream>
#define MEASURE(T,text) {\
cout<<text<<"\t";\
cout<<sizeof(T)<<"\t";\
int lastp=0;\
for (int i=0;i<11;i++){\
T *p=new T;\
int thisp=(int)p;\
if (lastp!=0) cout<<" "<<thisp-lastp;\
lastp=thisp;\
}\
cout<<"n";\
}
using namespace std;
template <class T>
void measure(char *text)
{
cout<<"measure"<<text<<"\t";
cout<<sizeof(text)<<"\n";
}
int main() {
return 0;
}
As a final, not directly bug-related question to you - why are you using a #define like this? Why not simply write the #define code into the measure method? #defineis usually used to give a short name for a variable or to declare very small functions - and there is a vocal part of the community that thinks they shouldn't be used at all!
In addition to Stephen's answer, I can say that #define is un-C++ish. It becomes useful when you need a variable name that corresponds to a string or something the like. For mostly all other cases, use functions.
Next to that, I must concur with DeadMG's opinion that at least I'm too stupid to see any reason to write this function. But that's another concern :)
If you actually want to measure the length of a string, you can use the function strlen.
What your MEASURE seems to do is print out a series of 11 newly allocated memory addresses. Nice to do when you are studying the memory allocation strategy of your runtime, but otherwise not too useful.
Also don't forget to delete what you have newed.
#define MEASURE(T,text) {\
cout<<text<<"\t";\
cout<<sizeof(T)<<"\t";\
...
can be directly translated into a template function: way easier to write, and to debug.
template< typename T > // assuming you _need_ a variable type of arguments
void MEASURE( const T& text) {
cout<<text<<"\t";
cout<<sizeof(T)<<"\t";
// will write the size of e.g. one character. Maybe
// you should use strlen or the like...
int lastp=0;
for (int i=0;i<11;i++){
T *p=new T;
int thisp=(int)p;
if (lastp!=0) cout<<" "<<thisp-lastp;
lastp=thisp;
}
cout<<"n";
}
"some" mistakes? Whoever wrote that has NFI what on earth they're doing. The program doesn't even produce any meaningful output. ... or any output at all. You could literally not run it or read the source code and gain the same knowledge: zero.
You need to add "\" at the end of the line when your definition across multiple lines.
Below code is compiled with no errors.
#include "stdafx.h"
#include <iostream>
using namespace std;
template <class T>
void measure(char *text)
{
cout<<"measure"<<text<<"\t";
cout<<sizeof(t)<<"\n";
}
#define MEASURE(T,text) { \
cout<<text<<"\t"; \
cout<<sizeof(T)<<"\t"; \
int lastp=0; \
for (int i=0;i<11;i++){ \
T *p=new T; \
int thisp=(int)p; \
if (lastp!=0) \
cout<<" "<<thisp-lastp; \
lastp=thisp; \
} \
cout<<"n": \
}
int main(){
return 0;
}
I'm reading this article on the Boost Unit Testing Framework.
However I'm having a bit of trouble with the first example, my guess is that they left something out (something that would be obvious to hardcore C++ coders) as IBM often does in their articles. Another possibility is that my Visual Studio 2005 C++ compiler is just too old for the example.
#include "stdafx.h"
#define BOOST_TEST_MODULE stringtest
#include <boost/test/unit_test.hpp>
//#include "mystring.h"
BOOST_AUTO_TEST_SUITE(stringtest) // name of the test suite is stringtest
BOOST_AUTO_TEST_CASE(test1)
{
/*
mystring s;
BOOST_CHECK(s.size() == 0);
*/
BOOST_CHECK(0 == 0);
}
BOOST_AUTO_TEST_CASE(test2)
{
/*
mystring s;
s.setbuffer("hello world");
BOOST_REQUIRE_EQUAL('h', s[0]); // basic test
*/
BOOST_CHECK(0 == 0);
}
BOOST_AUTO_TEST_SUITE_END()
To me the BOOST_AUTO_TEST_SUITE and BOOST_AUTO_TEST_CASE lines look a little suspect (especially since they don't have quotes around the arguments, and they are undeclared identifiers...but this probably means they are macros and I'm not certain I understand the concept or if that is available in VC++ 8.0)...
#ifdef _MYSTRING
#define _MYSTRING
class mystring {
char* buffer;
int length;
public:
void setbuffer(char* s) { buffer s = s; length = strlen(s); }
char& operator[ ] (const int index) { return buffer[index]; }
int size() {return length; }
}
#endif
Is there any reason why this code won't work?
1>c:\users\andy\documents\visual studio 2005\projects\unittesttests\unittesttests\unittesttests.cpp(7) : error C2065: 'stringtest' : undeclared identifier
1>c:\users\andy\documents\visual studio 2005\projects\unittesttests\unittesttests\unittesttests.cpp(9) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\andy\documents\visual studio 2005\projects\unittesttests\unittesttests\unittesttests.cpp(9) : error C2146: syntax error : missing ';' before identifier 'BOOST_AUTO_TEST_CASE'
1>c:\users\andy\documents\visual studio 2005\projects\unittesttests\unittesttests\unittesttests.cpp(9) : error C2065: 'test1' : undeclared identifier
1>c:\users\andy\documents\visual studio 2005\projects\unittesttests\unittesttests\unittesttests.cpp(10) : error C2448: 'BOOST_AUTO_TEST_CASE' : function-style initializer appears to be a function definition
1>c:\users\andy\documents\visual studio 2005\projects\unittesttests\unittesttests\unittesttests.cpp(18) : error C2065: 'test2' : undeclared identifier
1>c:\users\andy\documents\visual studio 2005\projects\unittesttests\unittesttests\unittesttests.cpp(19) : error C2448: 'BOOST_AUTO_TEST_CASE' : function-style initializer appears to be a function definition
1>c:\users\andy\documents\visual studio 2005\projects\unittesttests\unittesttests\unittesttests.cpp(29) : fatal error C1004: unexpected end-of-file found
Looks correct to me. My Boost.Test code looks the same way. I'm running VS2008, but I know it works in 2005 as well.
Seems like your problem lies elsewhere.
If you use precompiled headers (and why do you do that in such a small test program?), shouldn't stdafx.h be included as the very first thing in the file?
And what is the first line for? You don't seem to use it, and _MYSTRING is a reserved name in C++ (everything that begins with underscore followed by a capital letter is off limits)