C++ - expected unqualified-id before " /" token?

H

hon123456

Dear all,
Please bear with me, I am new to C++ programming to
windows . What I am trying is build a simple window. And I am using g+
+ .I have the following program run with the error:
simplewnd.cpp:221: error: expected unqualified-id before " /"
token.

The code is as follows:

//
=============================================================================
//SIMPLE WINDOW - Copyright © 2000,2005 Ken Fitlike
//
=============================================================================
//API functions used:
CreateWindowEx,DefWindowProc,DispatchMessage,GetMessage,
//
GetSystemMetrics,LoadImage,MessageBox,PostQuitMessage,RegisterClassEx,
//ShowWindow,UpdateWindow,TranslateMessage,WinMain.
//
=============================================================================
//This creates a window, half the height and half the width of the
desktop
//which is centred on the desktop.
//
//WinMain is the entry point function for winapi applications
(equivalent to
//main). _tWinMain is a placeholder for WinMain (non-unicode fn) or
wWinMain
//(unicode) but, since there is currently no wWinMain defined for
MinGW just
//use WinMain; if a unicode command line string is required then use
the
//GetCommandLine api function.
//
=============================================================================
#include <windows.h> //include all the basics
#include <tchar.h> //string and other mapping macros
#include <string>

//define an unicode string type alias
typedef std::basic_string<TCHAR> ustring;
//
=============================================================================
//message processing function declarations
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);

//non-message function declarations
inline int ErrMsg(const ustring&);
//
=============================================================================
int WINAPI WinMain(HINSTANCE hInst,HINSTANCE,LPSTR pStr,int nCmd)
{
ustring classname=_T("SIMPLEWND");
WNDCLASSEX wcx={0}; //used for storing information about the wnd
'class'

wcx.cbSize = sizeof(WNDCLASSEX);
wcx.lpfnWndProc = WndProc; //wnd Procedure pointer
wcx.hInstance = hInst; //app instance
//use 'LoadImage' to load wnd class icon and cursor as it supersedes
the
//obsolete functions 'LoadIcon' and 'LoadCursor', although these
functions will
//still work. Because the icon and cursor are loaded from system
resources ie
//they are shared, it is not necessary to free the image resources
with either
//'DestroyIcon' or 'DestroyCursor'.
wcx.hIcon = reinterpret_cast<HICON>(LoadImage
(0,IDI_APPLICATION,
IMAGE_ICON,
0,0,LR_SHARED));
wcx.hCursor = reinterpret_cast<HCURSOR>(LoadImage(0,IDC_ARROW,
IMAGE_CURSOR,
0,0,LR_SHARED));
wcx.hbrBackground = reinterpret_cast<HBRUSH>(COLOR_BTNFACE+1);
wcx.lpszClassName = classname.c_str();
//the window 'class' (not c++ class) has to be registered with the
system
//before windows of that 'class' can be created
if (!RegisterClassEx(&wcx))
{
ErrMsg(_T("Failed to register wnd class"));
return -1;
}

int desktopwidth=GetSystemMetrics(SM_CXSCREEN);
int desktopheight=GetSystemMetrics(SM_CYSCREEN);

HWND hwnd=CreateWindowEx(0, //extended styles
classname.c_str(), //name: wnd 'class'
_T("Simple Window"), //wnd title
WS_OVERLAPPEDWINDOW, //wnd style
desktopwidth/4, //position:left
desktopheight/4, //position: top
desktopwidth/2, //width
desktopheight/2, //height
0, //parent wnd handle
0, //menu handle/wnd id
hInst, //app instance
0); //user defined info
if (!hwnd)
{
ErrMsg(_T("Failed to create wnd"));
return -1;
}

ShowWindow(hwnd,nCmd);
UpdateWindow(hwnd);
//start message loop - windows applications are 'event driven' waiting
on user,
//application or system signals to determine what action, if any, to
take. Note
//that an error may cause GetMessage to return a negative value so,
ideally,
//this result should be tested for and appropriate action taken to
deal with
//it(the approach taken here is to simply quit the application).
MSG msg;
while (GetMessage(&msg,0,0,0)>0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return static_cast<int>(msg.wParam);
}
//
=============================================================================
LRESULT CALLBACK WndProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM
lParam)
{
switch (uMsg)
{
case WM_DESTROY:
PostQuitMessage(0); //signal end of application
return 0;
default:
//let system deal with msg
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
}
//
=============================================================================
inline int ErrMsg(const ustring& s)
{
return MessageBox(0,s.c_str(),_T("ERROR"),MB_OK|MB_ICONEXCLAMATION);
}
//
=============================================================================
 
B

Balog Pal

"hon123456" <[email protected]>
simplewnd.cpp:221: error: expected unqualified-id before " /" token.

The code is as follows:

your code has only 141 lines even with those extra line breaks the news
inserted...
 
H

hon123456

"hon123456" <[email protected]>
 simplewnd.cpp:221: error: expected unqualified-id before " /" token..

The code is as follows:

your code has only 141 lines even with those extra line breaks the news
inserted...

That is the problem . So I guess the number is representing other
meaning. for other warning,it will like this:
simplewnd.cpp:221:3 error: expected unqualified-id before " /"
But for this error it only show as follows:
simplewnd.cpp:221: error: expected unqualified-id before " /"

So I cannot find out which line is having the problem.
Please help.
 
F

Fred Zwarts

hon123456 said:
Dear all,
Please bear with me, I am new to C++ programming to
windows . What I am trying is build a simple window. And I am using g+
+ .I have the following program run with the error:
simplewnd.cpp:221: error: expected unqualified-id before " /"
token.

I don't know this error message, but may be it is the following:
The code is as follows:

//
=============================================================================

The last line is not valid C++. The next line starts with /. The compiler expected something to follow the last =.
//SIMPLE WINDOW - Copyright © 2000,2005 Ken Fitlike
//
=============================================================================

Again an invalid line with multiple = followed by /.
 
F

Francesco S. Carta

That is the problem . So I guess the number is representing other
meaning. for other warning,it will like this:
simplewnd.cpp:221:3 error: expected unqualified-id before " /"
But for this error it only show as follows:
simplewnd.cpp:221: error: expected unqualified-id before " /"

So I cannot find out which line is having the problem.
Please help.

Hi there,
your code runs fine on my GCC 3.4.5 (after having fixed all those
broken // comments).

To spot your actual problem, try adding an evident error at the end of
your program, and then check out its line number in the corresponding
error message.

Maybe something weird is going on, such as an "unexpected" macro being
expanded. If you end up having errors with line numbers beyond that
added-last-error's line number, then probably something is going wrong
with your compiler, IDE or whatsoever.

Everything right off the top of my head, no guarantees.

In any case, take the habit to use /* */ comments when posting code
here.

To ensure that no comment gets broken, put the stop-comment character
combination on a separate line, in this way:

/* incredibly long comment
*/

In that way, you are ensured that no comment gets ever broken, and
will help people testing your code.

Hope that helps.

Have good time,
Francesco
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,961
Messages
2,570,130
Members
46,689
Latest member
liammiller

Latest Threads

Top