Android NDK with template<class T>

Put problems with the Android NDK in this forum.

Android NDK with template<class T>

Postby greglebad » Fri May 06, 2011 5:41 pm

Hi,

I'm using the NDK Android, modified with crystax-r5b, with the STL
(stlport_static)
I'm trying to use the template, but i'm facing with some errors that I
don't understand.

So I have write a .cpp file with a easy use of template

#include "Vector2.h"

/* functions for vectors */
namespace AS
{
template <class T>
CVector2<T>::CVector2(T _X, T _Y) :
X(_X),
Y(_Y)
{

}

}

And a .h file associated

#ifndef VECTOR2_H
#define VECTOR2_H

#include <math.h>
#include <typeinfo>
#include "../config/Define.h"
#include "../utilities/Utils.h"

namespace AS
{
template <class T> class CVector2;
typedef CVector2<i32> TVector2i; /** int type vector */
typedef CVector2<f32> TVector2f; /** float type vector */
/**
* @class CVector2
*
* @brief This class represents a vector with 2 components and
its main operations
*/
template <class T>
class CVector2
{
public :

/**
* @brief Default constructor
*
* @param _X : x component
* @param _Y : y component
*/
CVector2(T _X = 0, T _Y = 0);


/**
* @fn void set(T X, T Y)
*
* @brief Reinitializes the vector
*
* @param _X : x axis
* @param _Y : y axis
*/
void set(T _X, T _Y);

};

} /* namespace AS */


#endif /* VECTOR2_H */

And I have these errors.

In file included from /home/gbadoual/Workspace/proj/template/
android_os/android/jni/opengl.cpp:13:
/home/gbadoual/Workspace/proj/template/android_os/android/jni/
maths/Vector2.hpp:37: error: expected ',' or '...' before numeric
constant
/home/gbadoual/Workspace/proj/template/android_os/android/jni/
maths/Vector2.hpp:48: error: expected ',' or '...' before numeric
constant
make: *** [/home/gbadoual/Workspace/proj/template/android_os/
android/obj/local/armeabi/objs-debug/opengl/opengl.o] Erreur 1

So I want to know if I can use the template with the Android NDK. I
think it's allowed, because a lot of people succeed to use template<>
with android NDK.

And can you explain me if I'm doing something wrong. I have already
checked for this errors, and some people think that's because of a
redefinition of a macro #define. But here I use a namespace, so I
think this use case is avoid.

Can you help me ?
greglebad
Freshman
Freshman
 
Posts: 2
Joined: Fri May 06, 2011 5:40 pm

Top

Re: Android NDK with template<class T>

Postby greglebad » Mon May 09, 2011 9:54 am

Hi

I tried to change some things to be more close from the code that i used for an iPhone application that I have realised.

So there is the file and the errors :

/**
* @file Vector2.h
* @brief A container with 2 components
* @author Alternative Shift (Guillaume Rous)
* @date 30/11/09
*/

#ifndef VECTOR2_H
#define VECTOR2_H

#include <math.h>
#include <typeinfo>
#include "../config/Define.h"
#include "../utilities/Utils.h"

namespace AS
{
/**
* @class CVector2
*
* @brief This class represents a vector with 2 components and its
main operations
*/
template <class T>
class CVector2
{
public :

CVector2(T _X, T _Y);

};

template <typename T>
inline CVector2<T>::CVector2(T _X, T _Y) :
X(_X),
Y(_Y)
{

}

} /* namespace AS */

#endif /* VECTOR2_H */

And there is the errors :

In file included from /home/gbadoual/Workspace/proj/template/
android_os/android/jni/opengl.cpp:13:
/home/gbadoual/Workspace/proj/template/android_os/android/jni/maths/
Vector2.h:28: error: expected ',' or '...' before numeric constant
/home/gbadoual/Workspace/proj/template/android_os/android/jni/maths/
Vector2.h:33: error: expected ',' or '...' before numeric constant
/home/gbadoual/Workspace/proj/template/android_os/android/jni/maths/
Vector2.h: In constructor 'AS::CVector2<T>::CVector2(T)':
/home/gbadoual/Workspace/proj/template/android_os/android/jni/maths/
Vector2.h:34: error: class 'AS::CVector2<T>' does not have any field
named 'X'
/home/gbadoual/Workspace/proj/template/android_os/android/jni/maths/
Vector2.h:35: error: class 'AS::CVector2<T>' does not have any field
named 'Y'
/home/gbadoual/Workspace/proj/template/android_os/android/jni/maths/
Vector2.h:35: error: '_Y' was not declared in this scope
make: *** [/home/gbadoual/Workspace/proj/template/android_os/android/
obj/local/armeabi/objs-debug/opengl/opengl.o] Erreur 1

I want to know how to use template for Android NDK.
Because I try to port a code who was functionnal for C++ Compiler
(Unix), and for iPhone.
But I want to understand why the use of template, that I had before
doesn't work with the Android Compiler
greglebad
Freshman
Freshman
 
Posts: 2
Joined: Fri May 06, 2011 5:40 pm

Top

Return to NDK Problems

Who is online

Users browsing this forum: No registered users and 1 guest