A
Alessandro [AkiRoss] Re
Hello there!
While developing a policy-based application, I tried a code like this
one (which is real code).
I'm using g++ 4.3.3, which gives me these errors:
templ_error.cpp: In function ‘int main()’:
templ_error.cpp:22: error: multiple parameters named ‘base’
templ_error.cpp:23: error: request for member ‘exec’ in ‘test’, which
is of non-class type ‘Test<Numeric<3>, Numeric<5> > ()(Numeric<3>,
Numeric<5>)’
But I can't understand where is the problem: it seems that g++ read my
declaration of a variable as a function definition. Please tell me if
I'm doing it wrong: I can't see the error.
Here's the code of templ_error.cpp
#include <iostream>
using namespace std;
template <typename A, typename B>
struct Test {
A a;
B b;
Test(A a_, B b_): a(a_), b(b_) {}
void exec() { cout << "Executed!" << a() << "-" << b() <<"\n"; }
};
template <int X>
struct Numeric {
int base;
Numeric(int base_): base(base_) {}
int operator()() { return base + X; }
};
int main() {
int base = 1;
Test<Numeric<3>, Numeric<5> > test(Numeric<3>(base), Numeric<5>
(base));
test.exec();
return 0;
}
ps. Also with g++ 4.1 gives errors: the only difference is that
"multiple parameters name" is not present as it has introduced in gcc
4.3.
Any help is appreciated
Thanks!
Regards
While developing a policy-based application, I tried a code like this
one (which is real code).
I'm using g++ 4.3.3, which gives me these errors:
templ_error.cpp: In function ‘int main()’:
templ_error.cpp:22: error: multiple parameters named ‘base’
templ_error.cpp:23: error: request for member ‘exec’ in ‘test’, which
is of non-class type ‘Test<Numeric<3>, Numeric<5> > ()(Numeric<3>,
Numeric<5>)’
But I can't understand where is the problem: it seems that g++ read my
declaration of a variable as a function definition. Please tell me if
I'm doing it wrong: I can't see the error.
Here's the code of templ_error.cpp
#include <iostream>
using namespace std;
template <typename A, typename B>
struct Test {
A a;
B b;
Test(A a_, B b_): a(a_), b(b_) {}
void exec() { cout << "Executed!" << a() << "-" << b() <<"\n"; }
};
template <int X>
struct Numeric {
int base;
Numeric(int base_): base(base_) {}
int operator()() { return base + X; }
};
int main() {
int base = 1;
Test<Numeric<3>, Numeric<5> > test(Numeric<3>(base), Numeric<5>
(base));
test.exec();
return 0;
}
ps. Also with g++ 4.1 gives errors: the only difference is that
"multiple parameters name" is not present as it has introduced in gcc
4.3.
Any help is appreciated
Thanks!
Regards