Audison Athena wrote on 24/09/2005 19:01:05: [...] > > class RandomGenObj { [...] > int main() { > vector<int> v1(10, 10); > RandomGenObj rg(); You have just declared a function named rg, that accepts void and returns RandomGenObj by value. C++'s ambiguity is a great thing, isn't it? > random_shuffle(v1.begin(), v1.end(), rg); You are passing random_shuffle the wrong type, you are passing it a pointer to function that returns RandomGenObj, instead of a functor (or a function) that accepts an int and returns an int. [...] > Above is the test program, I compiled it under gcc version 4.0.0 > 20050519(Red Hat 4.0.0-8), and the compiler output as follow: > > /usr/lib/gcc/i386-redhat-linux/4.0.0/../../../../include/c > ++/4.0.0/bits/stl_algo.h: In function ‘void > std::random_shuffle(_RandomAccessIterator, _RandomAccessIterator, > _RandomNumberGenerator&) [with _RandomAccessIterator = > __gnu_cxx::__normal_iterator<int*, std::vector<int, std::allocator<int> > > >, _RandomNumberGenerator = RandomGenObj ()()]’: The above line tells you that the last argument to the function is of type RandomGenObj ()(), which is a function that accepts no arguments and returns RandomGenObj. [...] > ++/4.0.0/bits/stl_algo.h:1793: error: no match for ‘operator+’ in > ‘__first + (+ __rand)()’ The above error is more hard to understand, because it does not tell you in what way __rand's type is wrong. [...] > however, if I rewrite the second line in function main as follow: > RandomGenObj rg; > Then the compiler pass the program, everything is right. It's because does no longer look like function declaration. It is no longer ambiguous. > due to my limit knowledge in C++, I can't assure if it's due to > compiler's own problem. > I think in syntax there's no difference between "RandomGenObj rg;" and > "RandomGenObj rg()", since it has a default constructor. It is ambiguous. What if you wanted to declare a function RandomGenObj func(); and the compiler would generate an object named func instead? Michael