Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
7956 Discussions

error: expected a ';" . Why do I get this error?

jiandong
Beginner
435 Views
When compiling a class in a linux machine, I got theerror message " error: expected a ";" ". The class is compiled fine using VS 2005 in Windows. The following isthe simplified version of the class. The error is from the first line of the Find() function. I cann't findwhy I get this error. The compiler version is 9.1.043


template class MyClass
{
public:
MyClass() {};
~MyClass(void) {};

T* Find(int nKey) {
map::const_iterator it = m_map.find(nKey);
return it == m_map.end() ? NULL : it->second;
};

map m_map;
};

-----------------------------------------------------------
error: expected a ";"
map::const_iterator it = m_map.find(nKey);
^

0 Kudos
2 Replies
JenniferJ
Moderator
435 Views
do you have your own "map" template? I tried it, it works for me on IA32.

$ icpc -V
Intel C++ Compiler for 32-bit applications, Version 9.1 Build 20060816Z Package ID: l_cc_c_9.1.043
Copyright (C) 1985-2006 Intel Corporation. All rights reserved.

$ cat t.cpp
#include
using namespace std;

template class MyClass
{
public:
MyClass() {};
~MyClass(void) {};

T* Find(int nKey) {
map::const_iterator it = m_map.find(nKey);
return it == m_map.end() ? NULL : it->second;
};

map m_map;
};

$ icpc -c t.cpp
$ icc -c t.cpp
$

0 Kudos
jiandong
Beginner
435 Views
do you have your own "map" template? I tried it, it works for me on IA32.

$ icpc -V
Intel C++ Compiler for 32-bit applications, Version 9.1 Build 20060816Z Package ID: l_cc_c_9.1.043
Copyright (C) 1985-2006 Intel Corporation. All rights reserved.

$ cat t.cpp
#include
using namespace std;

template class MyClass
{
public:
MyClass() {};
~MyClass(void) {};

T* Find(int nKey) {
map::const_iterator it = m_map.find(nKey);
return it == m_map.end() ? NULL : it->second;
};

map m_map;
};

$ icpc -c t.cpp
$ icc -c t.cpp
$


Thank you for your quick reply. I finally find what is missing. For template argument dependent name, the 'typename' keyword is neededin front of it. Now it becomes:

typename map::const_iterator it = m_map.find(nKey);

And it works fine now.

Thanks again for your help.


0 Kudos
Reply