- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm trying to write a simple template function that takes two floating-point values x and y as arguments and returns fmod(x, y):
#include
#include
template
T foo(T x, T y) {
return fmod(x, y);
}
int main(int argc, char* argv[]) {
float x = 4.0, y = 1.0;
double a = 3.5, b = 9.2;
std::cout << "foo(" << x << ", " << y << ") = " << foo
std::cout << "foo(" << a << ", " << b << ") = " << foo
}
When I try to compile, I get a number of errors like:
1>.\main.cpp(14): error: expected an expression
1> return fmod(x, y);
1> ^
1> detected during instantiation of "T foo(T, T) [with T=float]" at line 21
Any ideas what this error message means? Thanks.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
#include
#include
template
T foo(T x, T y) {
return fmod(x, y);
}
int main(int argc, char* argv[]) {
float x = 4.0, y = 1.0;
double a = 3.5, b = 9.2;
std::cout << "foo(" << x << ", " << y << ") = " << foo
std::cout << "foo(" << a << ", " << b << ") = " << foo
}
1>.main.cpp(14): error: expected an expression
1> return fmod(x, y);
1> ^
1> detected during instantiation of "T foo(T, T) [with T=float]" at line 21
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I tried switching #include
So my next question is, how can I use the functionality from
Also, in
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
C99 doesn't understand C++ syntax, such as any usage of
ICL doesn't do much in the way of adding functions, it simply uses those provided by VC, so you don't get library support when you set /Qlong-double in ICL.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
the same for copysign
http://msdn.microsoft.com/en-us/library/aa246720.aspx
#include
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
the same for copysign
http://msdn.microsoft.com/en-us/library/aa246720.aspx
#include
Wow you're right, I can't believe I missed that...however, I also need erf(), which MSVC doesn't seem to provide (I hope I'm right about this one, I actually checked this time). Which leaves me with the same issue as before. Tim's answer clarified why I can't use
catastrophic error: #error directive: "
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Wow you're right, I can't believe I missed that...however, I also need erf(), which MSVC doesn't seem to provide (I hope I'm right about this one, I actually checked this time). Which leaves me with the same issue as before. Tim's answer clarified why I can't use
catastrophic error: #error directive: "
Agreed, the documentation is confusing on this point. Apparently,
ICL links againstits ownlibm.h; the long double functions are hidden (replaced by double) unless we set /Qlong-double /Qpc80 and use
As the doc on Qlong-double says, there is no printf support for 80-bit long double in any Intel or Microsoft Windows library.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page