mardi 5 janvier 2016

C++/ name conflict: how to exclude a previously defined function

I want to write log2() function for a new datatype that I defined myself Array. So it will look like this

#include <iostream>
#include <cmath>

Array log2(Array& A)
{
    Array C=A;

    for (int i=0; i<A.size(); i++)
         C[i]=log2(A[i]);

    return C;
}

despite other functions like sin, cos, etc, this one (log2) is not declared under std namespace. so even using the following

std::log2(A[i])

the compiler does not resolve that inside log2 is suppoed to be the built-in c function. I persist to use the same name (log2) for simplicity of the code.

This is the error message

error: invalid initialization of reference of type 'Array&' from expression of type 'double'

UPDATE: It worked when I switched to -std::C++ 11.

Aucun commentaire:

Enregistrer un commentaire