I have an issue compiling my code on windows.
On Unix-based systems all is working fine, but when I compile it on windows (currently with visual studio 2010 express), I'm getting the following errors:
Error 253 error C2146: syntax error : missing ';' before identifier 'N0' C:\ghost++\ghost\ohconnect.h 45
Error 254 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int C:\ghost++\ghost\ohconnect.h 45
Error 255 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int C:\ghost++\ghost\ohconnect.h 45
Error 256 error C2146: syntax error : missing ';' before identifier 'N' C:\ghost++\ghost\ohconnect.h 46
Error 257 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int C:\ghost++\ghost\ohconnect.h 46
And so on.
I think it's all relating to my header file, the class itself is made to connect to websockets:
#ifndef OHConnect_H
#define OHConnect_H
//
// OHCONNECT
//
class CTCPClient;
class CBaseGame;
class CCommandPacket;
struct OHCHeader {
unsigned header_size;
bool fin;
bool mask;
enum opcode_type {
CONTINUTATION = 0x0,
TEXT_FRAME = 0x1,
BINARY_FRAME = 0x2,
CLOSE = 8,
PING = 9,
PONG = 0xa,
} opcode;
uint64_t N0;
uint64_t N;
uint8_t masking_key[4];
};
In my .cpp file I'm using namespace std; and included <string> only for windows.
But all this didnt work so far. I didnt wanted to put the whole files into the question since they are actually long.
Here is the full source:
Headerfile
Mainfile
What did I wrong here?
The compiler doesn't know the type uint64_t and uint8_t, add:
#include <cstdint>
Note also that the trailing comma in the enum (after the definition PONG = 0xa) was only standardized in C++11, following the change made in C99. Older compilers or those running in a mode following the older 1998/2003 standard may trip over that as well.
Related
While migrating from Visual studio 2013 to Visual studio 2019 compiler I have got below error. Please help me in fixing the same.
I have declared the function in the header file (.h) below:
#ifndef CSAHCCOMPOSEDITEM_H
#define CSAHCCOMPOSEDITEM_H
#ifdef _UTEST
class CsaHcDICOMComposerTester;
#endif
class EXP_IMP_HcDicComp CsaHcComposedItem
{
#ifdef _UTEST
friend class CsaHcDICOMComposerTester;
#endif
public:
enum CsaHcComposedItemType
{
CISegment,
CIPage,
CILayout,
CIPageBracket,
CIPrintJobBracket,
CIDummy
};
CsaHcComposedItem
(bool &status, CsaHcComposedItemType type_in);
CsaHcComposedItem
();
CsaHcComposedItem a
(const CsaHcComposedItem& compObj_in);
CsaHcComposedItem& operator=
(const CsaHcComposedItem& compObj_in);
~CsaHcComposedItem();
bool operator==
(const CsaHcComposedItem& ci_in);
private: // attributes
CsaHcComposedItemType
myType;
CsaHcBasicFilmSession
*myBFS;
CsaHcBasicFilmBox
*myBFB;
CsaHcBasicImageBox
*myBIB;
CsaDib *myDib;
BYTE *myPixelArray;
};
#endif // CSAHCCOMPOSEDITEM_H
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
And cpp file contains the definition for the constructor.
//pusedo code
CsaHcComposedItem::CsaHcComposedItem(bool &status_out,
// Return status of the construcor
CsaHcComposedItemType type_in)
// Composed item type
: myType(type_in), // error shown for this line (70)
myBFS(NULL), //line71
myBFB(NULL),
myBIB(NULL),
myDib(NULL),
myPixelArray(NULL)
{
.....
}
Error:
1.CsaHcComposedItem.cpp(70): error C2761: '{ctor}': redeclaration of member is not allowed
2.CsaHcComposedItem.cpp(70): error C2059: syntax error: ':'
3.CsaHcComposedItem.cpp(70): error C2065: 'type_in': undeclared identifier
4.CsaHcComposedItem.cpp(70): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
5.CsaHcComposedItem.cpp(71): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
6.CsaHcComposedItem.cpp(72): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
7.CsaHcComposedItem.cpp(73): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
8.CsaHcComposedItem.cpp(74): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
9.CsaHcComposedItem.cpp(75): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
10.CsaHcComposedItem.cpp(78): error C2448: 'myPixelArray': function-style initializer appears to be a function definition
That source is compiled without error in VS2019(16.4.5)
I compiled with these declarations
#include <Windows.h>
#define EXP_IMP_HcDicComp
using CsaHcBasicFilmSession = int;
using CsaHcBasicFilmBox = int;
using CsaHcBasicImageBox = int;
using CsaDib = int;
Issue is fixed,
below line of code was not commented in my cpp file, after commenting it worked.
#include <iostream>
using namespace std;
int main()
{
cout<<"hello world!"<<endl;
return 0;
}
I am trying to run this simplest code in vs2010, but I received more than 100 errors when I was compiling it.
f:\vs2010\vc\include\fstream(14): error C2143: syntax error : missing ';' before '*'
f:\vs2010\vc\include\fstream(14): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
f:\vs2010\vc\include\fstream(16): error C2653: 'ios_base' : is not a class or namespace name
f:\vs2010\vc\include\fstream(16): error C2061: syntax error : identifier 'openmode'
f:\vs2010\vc\include\fstream(16): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
Errors like these. What should I do?
try to include this lab in your code
#include "stdafx.h"
I've declared a global enum type in my program and want various functions within my program to return instances of the enum type. Here is my declaration:
#ifndef GLOBAL_H_
#define GLOBAL_H_
#include <SDL.h>
#include "LTexture.h"
#include "LButton.h"
#include "Initializationetc.h"
enum LButtonSprite
{
BUTTON_SPRITE_MOUSE_OUT = 0,
BUTTON_SPRITE_MOUSE_OVER_MOTION = 1,
BUTTON_SPRITE_MOUSE_DOWN = 2,
BUTTON_SPRITE_TOTAL = 2
};
...
However, when I go try and build a function that returns "LButtonSprite" the following happens:
#ifndef LBUTTON_H
#define LBUTTON_H
#include <SDL.h>
#include "Global.h"
class LButton
{
public:
//Initializes internal variables
LButton();
//Sets top left position
void setPosition(int x, int y);
//Handles mouse event
void handleEvent(SDL_Event* e);
//Shows button sprite
void render();
LButtonSprite getCurrSprite();//here
private:
//Button Position
SDL_Point mPosition;
//Button Sprite
LButtonSprite mCurrentSprite; //and here.
};
#endif
It seems as if the Visual Studio is mistaking the function prototype LButtonSprite getCurrSprite(); for a declaration of a variable called getCurrSprite() of type LButtonSprite. The colour coding provided by VS (as seen above) seems to confirm this suspicion. Return types are blue, but LButtonSprite is light blue which is the colour reserved for variables.
The problem isn't just cosmetic unfortunately. I'm getting a bunch ofC4430: missing type specifier - int assumed. Note: C++ does not support default-int. I've added comments to the code at the lines where the error is occurring. The complete error log is included at the end of the post.
How can I correct this mistake?
Error log:
Error 2 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\users\adam\documents\visual studio 2013\projects\sdl2_tutorials\sdl2_tutorials\lbutton.h 22 1 SDL2_tutorials
Error 5 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\users\adam\documents\visual studio 2013\projects\sdl2_tutorials\sdl2_tutorials\lbutton.h 29 1 SDL2_tutorials
Error 8 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\users\adam\documents\visual studio 2013\projects\sdl2_tutorials\sdl2_tutorials\lbutton.h 22 1 SDL2_tutorials
Error 11 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\users\adam\documents\visual studio 2013\projects\sdl2_tutorials\sdl2_tutorials\lbutton.h 29 1 SDL2_tutorials
Error 14 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\users\adam\documents\visual studio 2013\projects\sdl2_tutorials\sdl2_tutorials\global.h 34 1 SDL2_tutorials
Error 17 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\users\adam\documents\visual studio 2013\projects\sdl2_tutorials\sdl2_tutorials\lbutton.h 22 1 SDL2_tutorials
Error 20 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\users\adam\documents\visual studio 2013\projects\sdl2_tutorials\sdl2_tutorials\lbutton.h 29 1 SDL2_tutorials
Error 4 error C2146: syntax error : missing ';' before identifier 'mCurrentSprite' c:\users\adam\documents\visual studio 2013\projects\sdl2_tutorials\sdl2_tutorials\lbutton.h 29 1 SDL2_tutorials
Error 10 error C2146: syntax error : missing ';' before identifier 'mCurrentSprite' c:\users\adam\documents\visual studio 2013\projects\sdl2_tutorials\sdl2_tutorials\lbutton.h 29 1 SDL2_tutorials
Error 19 error C2146: syntax error : missing ';' before identifier 'mCurrentSprite' c:\users\adam\documents\visual studio 2013\projects\sdl2_tutorials\sdl2_tutorials\lbutton.h 29 1 SDL2_tutorials
Error 1 error C2146: syntax error : missing ';' before identifier 'getCurrSprite' c:\users\adam\documents\visual studio 2013\projects\sdl2_tutorials\sdl2_tutorials\lbutton.h 22 1 SDL2_tutorials
Error 7 error C2146: syntax error : missing ';' before identifier 'getCurrSprite' c:\users\adam\documents\visual studio 2013\projects\sdl2_tutorials\sdl2_tutorials\lbutton.h 22 1 SDL2_tutorials
Error 16 error C2146: syntax error : missing ';' before identifier 'getCurrSprite' c:\users\adam\documents\visual studio 2013\projects\sdl2_tutorials\sdl2_tutorials\lbutton.h 22 1 SDL2_tutorials
Return types are blue
No – keywords are blue. Why else would enum, class, public and private be blue? Return types have no special syntax highlighting. The problem in your code is completely unrelated:
#ifndef GLOBAL_H_
#define GLOBAL_H_
#include <SDL.h>
#include "LTexture.h"
#include "LButton.h"
The last line includes (and thus declares) the LButton class, before you define your enum. Remove that line from the file, or define the enum before.
I'm assuming you use VS2012. In VS2012, all user defined types(return values are no exception) are colored light blue. Dark blue are reserved words.
The reason why your function's return type is light blue is because the return type is a user defined type.
From your code I see you have #include "LButton.h" probably containing the definition of class LButton before declaration of the enum LButtonSprite, therefore the IDE and the compiler does not see the LButtonSprite declared in the LButton, hence the wrong coloring.
You should include it the other way around, LButtonSprite.h into LButton.h
I use Visual Studio 2005
When I compile, I get this error:
Error 1 error C2146: syntax error : missing ';' before identifier 'mDropEndTime'
Error 2 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
struct MB_SYN_DROPITEM_UPDATE : MSGBUF
{
long mCid; // Index
unsigned long mItemIdx; // idx
TIMESTAMP_STRUCT mDropEndTime; // This is error line
};
Why doesn't C++ know TIMESTAMP_STRUCT?
TIMESTAMP_STRUCT is something defined in sqlext.h
You must add
#include <sqlext.h>
Because TIMESTAMP_STRUCT is not part of the C++ standard.
below mentioned is my c++/cli "*.h" file
// rmsCInterfaceWrapper.h
#ifndef RMSCINTERFACE_H
#define RMSCINTERFACE_H
#ifndef RMSREQINFO_H
#define RMSREQINFO_H
#ifndef RMSCLIENTINFO_H
#define RMSCLIENTINFO_H
#ifndef RMSPHYSICIANINFO_H
#define RMSPHYSICIANINFO_H
#ifndef RMSREQPOLICYINFO_H
#define RMSREQPOLICYINFO_H
#pragma once
#include "D:\nbsource code\RMS\rmsCAPI\rmsCInterface.h"
#pragma comment(lib,"rmsCAPI.lib")
#include "D:\nbsource code\RMS\rmsDLL\rmsReqInfo.h"
#include "D:\nbsource code\RMS\rmsDLL\rmsClientInfo.h"
#include "D:\nbsource code\RMS\rmsDLL\rmsPhysicianInfo.h"
#include "D:\nbsource code\RMS\rmsDLL\rmsReqPolicyInfo.h"
#pragma comment(lib,"rmsDLL.lib")
using namespace System;
namespace rmsCInterfaceWrapper
{
public ref class rmsCInterface
{
// TODO: Add your methods for this class here.
private:
rmsReqInfoStruct *rmsReqInfo;
rmsClientInfoStruct *rmsClientInfo;
rmsPhysicianInfoStruct *rmsPhysicianInfo;
rmsReqPolicyInfoStruct *rmsReqPolInfo;
rmsAddlOrderInfoStruct *rmsAddOrderInfo;
public:
rmsCInterface();
~rmsCInterface();
long OrderReq();
};
}
#endif
i have declared pointer for these native c++ structures rmsReqInfoStruct, rmsClientInfoStruct, rmsPhysicianInfoStruct, rmsReqPolicyInfoStruct, rmsAddlOrderInfoStruct. wheni compile this i am getting these below mentioned errors and i am not sure why i am getting those
1>d:\vamsi\rmscinterfacewrapper\rmscinterfacewrapper\rmsCInterfaceWrapper.h(30) : error C2143: syntax error : missing ';' before '*'
1>d:\vamsi\rmscinterfacewrapper\rmscinterfacewrapper\rmsCInterfaceWrapper.h(30) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\vamsi\rmscinterfacewrapper\rmscinterfacewrapper\rmsCInterfaceWrapper.h(30) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\vamsi\rmscinterfacewrapper\rmscinterfacewrapper\rmsCInterfaceWrapper.h(31) : error C2143: syntax error : missing ';' before '*'
1>d:\vamsi\rmscinterfacewrapper\rmscinterfacewrapper\rmsCInterfaceWrapper.h(31) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\vamsi\rmscinterfacewrapper\rmscinterfacewrapper\rmsCInterfaceWrapper.h(31) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\vamsi\rmscinterfacewrapper\rmscinterfacewrapper\rmsCInterfaceWrapper.h(32) : error C2143: syntax error : missing ';' before '*'
1>d:\vamsi\rmscinterfacewrapper\rmscinterfacewrapper\rmsCInterfaceWrapper.h(32) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\vamsi\rmscinterfacewrapper\rmscinterfacewrapper\rmsCInterfaceWrapper.h(32) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\vamsi\rmscinterfacewrapper\rmscinterfacewrapper\rmsCInterfaceWrapper.h(33) : error C2143: syntax error : missing ';' before '*'
1>d:\vamsi\rmscinterfacewrapper\rmscinterfacewrapper\rmsCInterfaceWrapper.h(33) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\vamsi\rmscinterfacewrapper\rmscinterfacewrapper\rmsCInterfaceWrapper.h(33) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\vamsi\rmscinterfacewrapper\rmscinterfacewrapper\rmsCInterfaceWrapper.h(34) : error C2143: syntax error : missing ';' before '*'
1>d:\vamsi\rmscinterfacewrapper\rmscinterfacewrapper\rmsCInterfaceWrapper.h(34) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\vamsi\rmscinterfacewrapper\rmscinterfacewrapper\rmsCInterfaceWrapper.h(34) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
All these errors are showing up at the structure pointers in the class private declaration itself and i am unable to figure them out why they are causing. can any one please help.
I was able to solve the issue. As i have created a clr--->class library project it automatically generated the stdafx.h and stdafx.cpp files. As i am writing a wrapper around my native c++ code using c++/cli i copied the auto generated c++/cli stdafx.h file with my native stdafx.h file and removed the #ifndef,#define,#pragma statements from the .h file that i have provided above, so doing all these it worked, and i was able to generate the dll file which i can use in my c# program as a reference... Thank you every one for your help...