Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'powf' is not a member of 'std'

Tags:

c++

std

I have an error while compiling a library using XCode:

'powf' is not a member of 'std'

The <cmath> is included.

Can someone explain to me what is going wrong?

like image 630
Ziggy Avatar asked Mar 30 '11 08:03

Ziggy


2 Answers

Up until C++11, powf was just a Microsoft-ism. It did not appear in the ISO standard at all so is unlikely to be in XCode unless they were to adapt Microsoft's bizarre practices, something I would think unlikely.

pow, on the other hand, has been part of the C++ library for longer by virtue of the fact that it's in earlier iterations of the C library that is incorporated into C++ pre-11. Use that instead.

Since C++11, powf does appear in the ISO standard and is part of the std namespace.

Nevertheless, there are non-compliant implementations e.g., gcc libstdc++. More resources in this excerpt taken from a discussion in cppreference talk page:

Answers posted above were correct before C++11, since C++98/03 hadn't referred C99 library yet. According to the current standard, powf is declared in namespace std when is included (explicitly mentioned since C++17, implicitly mentioned in C++11/14, see also N4659, N4140 and N3337). For std::powf, gcc libstdc++ is not compliant while clang libc++ is. --Fruderica (talk) 03:49, 19 February 2019 (PST)

See also this, more recent, SO answer: https://stackoverflow.com/a/54735351 --Cubbi (talk) 08:10, 19 February 2019 (PST)

like image 116
paxdiablo Avatar answered Sep 27 '22 20:09

paxdiablo


Use just pow - powf isn't standard.

like image 40
Erik Avatar answered Sep 27 '22 19:09

Erik