The following code is not accepted by GCC 4.6:
void F(int x,char y) { } template<typename T> void G(T t) { F(t); } void F(int x) { } int main() { G(5); return 0; }
Should it be?
If not, does anyone have a good idea for the job? The real-world scenario where this happens is where G is part of the library for solving a specific problem requiring an auxiliary function provided by the user called F. However, for different types of problems, F takes a different number of parameters. A few examples of the implementation of F come with the library.
What happens is that, depending on the # include-order used by the client, only the “wrong view” F can be seen when the template is declared, and GCC then refuses, without waiting for the user to be given, correctly, F is defined. This is even though the creation of the template occurs after determining the correct F.
Update: Yes, I know that this works if all F declarations occur before G or all F declarations occur after G. However, this does not help me much.
Update: in the code this minimal example is adapted, F is really called "read". And the first reading announcement has nothing to do with the second. The first declaration is in one header file, and the second is in another. I don’t want to introduce “strange” rules regarding the order of include files, especially when the “read” versions have nothing to do with each other.
avl_sweden
source share