mercredi 23 décembre 2015

std::array

I have class which has a std::array as member variable like this:

class my_class{
std::array<point<float>,4> corners;
}

I need to pass these corners to many functions. Those functions accept (point<T>* const). So, I simply pass corners.data(). The Problem is when some function accept a special type of the point class. For example, (point<double>* const). How should I pass the corners to that function with the less possible performance overhead.

Code:

class my_class{
public:
std::array<point<float>,4> corners;
}
void first_method(point<float>* const input);
void second_method(point<float>* const input);

int main(){
    my_class foo;
    first_method(foo.corners.data()); // OK  
    second_method(foo.corners.data()); // Problem
}

EDIT:

I have just realized that the class has nothing to do with my problem we can reduce it to:

void first_method(point<float>* const input);
void second_method(point<float>* const input);

int main(){
    std::array<point<float>,4> corners;
    first_method(corners.data()); // OK  
    second_method(corners.data()); // Problem
}

Aucun commentaire:

Enregistrer un commentaire