4

When compiling my C++ for an iOS project, all proceeds just fine. However, I'm encountering difficulties on Android.

My Application.mk reads:

APP_ABI := armeabi armeabi-v7a
APP_PLATFORM := android-11
APP_STL := stlport_shared

All the LOCAL_SRC_FILES are defined.

When I try to build my module I get the following compiler error:

jni/Game.hpp: In member function 'const std::pair<pos, Obj*>* MyEnumerator::next()':
jni/Game.hpp:126:23: error: expected type-specifier
jni/Game.hpp:126:23: error: cannot convert 'int*' to 'std::pair<pos, Obj*>*' in assignment
jni/Game.hpp:126:23: error: expected ';'

The line of code referred to above reads:

this->ptr = new pair<pos, Obj*>::pair(it->first, it->second);

Here, ptr is of type pair<pos, Obj*>* and pos is a struct. I've declared using std::pair;.

Any hints on what is wrong, and what to try?

Ken
  • 30,811
  • 34
  • 116
  • 155
  • 3
    Does the error message refer to a C++ file and line#? If so, please post the relevant code. – paulsm4 Dec 17 '12 at 02:43
  • 1
    what is "pos", a type or an object? Because it appears to be an object, and if that is the case it will not work. – Jonathan Henson Dec 17 '12 at 02:54
  • "pos" is a struct. But like I say, the project builds fine with the default compiler over in iOS. – Ken Dec 17 '12 at 02:56
  • 1
    Also, what is the type of "ptr"? – Jonathan Henson Dec 17 '12 at 02:56
  • "ptr" is of type `pair*`. – Ken Dec 17 '12 at 02:57
  • 1
    try changing the line to read: this->ptr = new std::pair(it->first, it->second); – Jonathan Henson Dec 17 '12 at 02:59
  • I've declared the `pair` namespace, although I did try `std::` here too and no change. – Ken Dec 17 '12 at 03:01
  • 1
    well, I would recommend loosing all of the usings directives, period and use fully qualified names. But, also, the line you posted is wrong on most compilers, it should read exactly what I posted in my previous comment. Have you tried that exact text? – Jonathan Henson Dec 17 '12 at 03:02
  • @jonathan you're right, I just read your comment again (it's more than about namespaces, my line is wrong on most compilers such as the one I'm using here!). If you post your comment as an answer I'll accept it and vote it up. – Ken Dec 17 '12 at 03:04
  • Good, I added that as my answer. Glad to help. – Jonathan Henson Dec 17 '12 at 03:05

1 Answers1

4

try changing the line to read:

this->ptr = new std::pair<pos, Obj*>(it->first, it->second);

Also IMHO, lose the using directives and use fully qualified names. It is clean, precise, and doesn't allow for naming collisions. If you must use them, don't use them in header files, just in your implementation files.

Jonathan Henson
  • 8,076
  • 3
  • 28
  • 52