?
=?ISO-8859-1?Q?Ney_Andr=E9_de_Mello_Zunino?=
Hello.
The following program:
#include <list>
#include <iterator>
#include <algorithm>
#include <cmath>
#include <iostream>
int main()
{
using namespace std;
float elem[] = { 4, 7, 2, 8, 12 };
list<float> val(elem, elem + sizeof elem / sizeof elem[0]);
cout << "ORIGINAL\n\t";
copy(val.begin(), val.end(), ostream_iterator<float>(cout, "\n\t"));
transform(val.begin(), val.end(), val.begin(), log);
cout << "\nTRANSFORMED\n\t";
copy(val.begin(), val.end(), ostream_iterator<float>(cout, "\n\t"));
cout << '\n';
}
fails to compile in g++ 4.0, giving the following error message:
tran.cpp: In function `int main()':
tran.cpp:17: no matching function for call to `transform(
std::_List_iterator<float, float&, float*>, std::_List_iterator<float,
float&, float*>, std::_List_iterator<float, float&, float*>, <unknown
type>
)'
"Unknown type"?! I wondered why the compiler was not being able to
deduce it. Nothing occurred to me except the fact that the std::log
function (as most other math functions) has a handful of overloaded
versions. Could that be causing the compiler to get confused?
I then decided to try the same code in VC++ 8.00 on Windows. The program
compiles and produces the following expected results:
ORIGINAL
4
7
2
8
12
TRANSFORMED
1.38629
1.94591
0.693147
2.07944
2.48491
I would appreciate if anyone could let me know whether that program is
valid.
Thank you,
The following program:
#include <list>
#include <iterator>
#include <algorithm>
#include <cmath>
#include <iostream>
int main()
{
using namespace std;
float elem[] = { 4, 7, 2, 8, 12 };
list<float> val(elem, elem + sizeof elem / sizeof elem[0]);
cout << "ORIGINAL\n\t";
copy(val.begin(), val.end(), ostream_iterator<float>(cout, "\n\t"));
transform(val.begin(), val.end(), val.begin(), log);
cout << "\nTRANSFORMED\n\t";
copy(val.begin(), val.end(), ostream_iterator<float>(cout, "\n\t"));
cout << '\n';
}
fails to compile in g++ 4.0, giving the following error message:
tran.cpp: In function `int main()':
tran.cpp:17: no matching function for call to `transform(
std::_List_iterator<float, float&, float*>, std::_List_iterator<float,
float&, float*>, std::_List_iterator<float, float&, float*>, <unknown
type>
)'
"Unknown type"?! I wondered why the compiler was not being able to
deduce it. Nothing occurred to me except the fact that the std::log
function (as most other math functions) has a handful of overloaded
versions. Could that be causing the compiler to get confused?
I then decided to try the same code in VC++ 8.00 on Windows. The program
compiles and produces the following expected results:
ORIGINAL
4
7
2
8
12
TRANSFORMED
1.38629
1.94591
0.693147
2.07944
2.48491
I would appreciate if anyone could let me know whether that program is
valid.
Thank you,