c++11 - C++/ name conflict: how to exclude a previously defined function -
i want write log2() function new datatype defined myself array. this
#include <iostream> #include <cmath> array log2(array& a) { array c=a; (int i=0; i<a.size(); i++) c[i]=log2(a[i]); return c; } despite other functions sin, cos, etc, 1 (log2) not declared under std namespace. using following
std::log2(a[i]) the compiler not resolve inside log2 suppoed built-in c function. persist use same name (log2) simplicity of code.
this error message
error: invalid initialization of reference of type 'array&' expression of type 'double'
solved: worked when switched -std::c++ 11.
std::log2 introduced in c++11. make sure have c++11 compliant compiler (e.g. gcc4.8 or later, compile -std=c++11), , use std::log2 inside function.
if don't use std::log2, compiler cannot find standard function (as not using namespace std;) , tries use yours, of course not defined doubles, , error.
my personal opinion should try avoid naming function same standard one, due headaches can later appear.
Comments
Post a Comment