Solved

Which #include(s) are necessary for CMap

Posted on 2010-08-27
4
415 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 31

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 31

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
windows 10 how make picture as desktop background 2 73
FizzBuzz challenge 9 87
Detect file exist or not 3 215
Not needed 13 134
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 …
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

751 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