Solved

Which #include(s) are necessary for CMap

Posted on 2010-08-27
4
416 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
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…
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.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

635 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