Solved

Which #include(s) are necessary for CMap

Posted on 2010-08-27
4
413 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 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
centeredAverage challenge 8 179
lucky13 challenge 11 154
haveThree challenge 22 121
Unix Command -- Challenging  question 7 96
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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 video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

861 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