Solved

Which #include(s) are necessary for CMap

Posted on 2010-08-27
4
409 Views
Last Modified: 2013-11-20
Dear all,

i encounter the following problem.

As specified in the documentation for CMap, i do include the following:

	#include "afxtempl.h"

Open in new window


Using

	CMap<CString*, CString*, int, int> map;

Open in new window


everything works as expected, but if i specify the number of elements for the constructor like

	CMap<CString*, CString*, int, int> map(16);

Open in new window


i receive three times a compilation error.

      error C2059: syntax error : 'constant'

It seems to me, that some other #include is missing.

Any ideas?

Best regards
sahl04
0
Comment
Question by:sahl04
  • 2
  • 2
4 Comments
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 33540246
Compiler Error C2059
Error Message syntax error : 'token'
 
The token caused a syntax error.
To determine the cause, examine not only the line listed in the error  message, but also the lines above it. The following example generates an error  message for the line declaring j, but the true  source of the error appears on the line just above it.
If examining the lines yields no clue to what the problem might be, try  commenting out the line listed in the error message and possibly several lines  above it.
If the error message occurs on a symbol immediately following a  typedef variable, check that the variable is defined in the source  code.
You may get C2059 if a symbol evaluates to nothing, as can occur when you  compile with /Dsymbol=.
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 33540273
ps.       the following line compiles without error message here.

 CMap<CString*, CString*, int, int> map(16);

0
 
LVL 30

Accepted Solution

by:
Zoppo earned 500 total points
ID: 33540384
Hi sahl04,

do you use this in a class declaration? If so this isn't possible, i.e.:

> class CTest
> {
>   CMap < CString*, CString*, int, int > map1; // OK
>   CMap < CString*, CString*, int, int > map2( 16 ); // Error C2059
> };

To initialize such a member you need to add it's constructor call to the classes constructors initialization list, i.e.:

> class CTest
> {
>   CMap < CString*, CString*, int, int > map1; // OK
>   CMap < CString*, CString*, int, int > map2; // Error C2059
> public:
>  CTest();
> };
>
> CTest::CTest()
> : map2( 16 )
> {
> }

Hope that helps,

ZOPPO
0
 
LVL 30

Expert Comment

by:Zoppo
ID: 33540387
Sorry, I forgot to delete the 'Error C2059' comment in the second sample ... just ignore it.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now