Broken function reference error?
AWLaFramboise@aol.com
AWLaFramboise@aol.com
Sun Dec 1 21:47:00 GMT 2002
Hi,
I have run across a weird peculiarity with regards to references to functions
in C++. The following code segment compiles and runs without problems, unless
you uncomment the inst_ref line.
---
template<typename function>
class myclass {
public:
myclass(function f) : func(f) {
}
function func;
};
template<typename function>
myclass<function> inst_value(function f) {
return myclass<function>(f);
}
template<typename function>
myclass<function> inst_ref(function &f) {
return myclass<function>(f);
}
void myfunction() {
}
int main() {
inst_value(myfunction);
// inst_ref(myfunction);
// uncomment the preceding line to get the weird error
return 0;
}
---
I'm using gcc 3.2 mingw on mingw/sys. Compiled with:
g++ -ansi -pedantic -Wall -W -Wfloat-equal -Wundef -Wshadow -Wpointer-arith -
Wcast-qual -Wcast-align -Wwrite-strings -Wold-style-cast -Woverloaded-virtual -
Wsign-promo -Wpacked -g3 -o functest functest.cpp
I get this diagnostic when compiling with the line uncommented:
functest.cpp: In instantiation of `myclass<void ()()>':
functest.cpp:28: instantiated from here
functest.cpp:6: field `myclass<void ()()>::func' invalidly declared function
type
Apparently, there is a difference in type between these two templates, but
GCC does not show it in any of the diagnostics (as far as I can see).
Whatever difference there is causing it to work with one, but not another,
and the error message is vague. Either way, I do not understand. If having
a function data member was a problem, I'd think that a non-ref function would
be a problem, not a ref.
Can someone help me figure out whats going wrong?
Thanks,
Aaron W. LaFramboise
awlaframboise@aol.com
More information about the Gcc
mailing list