4
4
4NATIC2010-12-25 17:05:02
C++ / C#
4NATIC, 2010-12-25 17:05:02

Help with an error in the template function code

There is this code:

#define GDMLExtReader_H 1

#ifndef _WIN32
 #include <map>
#endif

class GDMLExtReader : public G4GDMLReadStructure

{

template  Type* GetPtr(const G4String& name, const std::map<G4String, Type*>& l)
 { 
 Type* ret = 0;
 std::map<G4String, Type*>::const_iterator pos = l.find(name);

 
 if (pos != l.end())
 ret = pos->second;
 else
 {
 G4String err_mess = "Attribute: " + name + " NOT found !";

 G4Exception("GDMLExtReader", "ReadError", FatalException, err_mess);
 }

return ret;
 }

};

#endif


It compiles and works under Visual Studio, but when you try to compile using gcc under Ubuntu, it fails with an error:
In member function Type* GDMLExtReader::GetPtr(const G4String&, const std::map<G4String, Type*, std::less, std::allocator<std::pair<const G4String, Type*> > >&)':
include/GDMLExtReader.hh: error: expected ;' before pos'
include/GDMLExtReader.hh: error: pos' was not declared in this scope

If you create a variable in a function, and not an iterator, i.e. std::map<G4String, Type*> pos2, then everything works.
The error is shown at creation of the iterator.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
tzlom, 2010-12-25
@tzlom

#ifndef _WIN32
#include #endif
- why the hell is that, or do you think that GCC will self-compress the right library in the right place?
a very stupid question and unwillingness to read what the compiler writes

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question