Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Which #include(s) are necessary for CMap

Posted on 2010-08-27
4
Medium Priority
?
419 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 2000 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
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.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

704 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