views:

116

answers:

3

Hi,

I'm trying to include some C++ code into my iPhone project and I'm getting the following compiler error:

"error:expected initializer before '<' token"

at this code construct:

  template<typename T, P_UINT_32 BEG, bool OQ, bool OVR, bool DBG>
  P_UINT_32 EKType<T, BEG, OQ, OVR, DBG>::getSizeX() const {
    return n;
  }

It looks like the XCode compiler is not recognizing this as a valid C++ syntax. I have named my C++ files with .h and .mm, and I've set the types of the files to sourcecode.cpp.h and sourcecode.cpp.cpp

Anyone has an idea as to why I'm getting this error?

+1  A: 

You probably have the header being included by a .M file somewhere. It's amazing how these things can get pulled in, so make sure all of your .M files are renamed .MM.

Frank Krueger
thanks for your suggestion. I renamed all .m files to .mm, but still getting the same error.
subjective-c
You're going to have to look at your build log (Shift+Cmd+B). Look at which file is being compiled when the error is found (NOT which file is opened when you double-click the error). Then look at the inclusion chain to figureout whether any non MM files are being compiled.
Frank Krueger
Thanks. So, I'm looking at the build log and the file that's being compiled at the time or error is a .cpp file. That file includes a .h (c++) and that's it. Unless you mean something else by inclusion chain?
subjective-c
A: 

You only need to name a file .mm if the file contains both Objective-C and C++.

If the file only contains C++, it should have the extension .cpp

If the file is a mix of ObjC and C++, then it should have the extension .mm and have its type set as sourcecode.cpp.objcpp

Jasarien
yes, thanks. I changed them to .cpp but it made no difference
subjective-c
A: 

Are you sure that the source file you are trying to compile includes the declaration of the EKType class (or struct) and the declaration P_UINT_32?

I would think you'd get a similar error if the compiler wasn't aware of EKType or P_UINT_32.

Jon-Eric