This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: C++ bug: pointer to overloaded function


On Fri, Jul 09, 1999 at 05:01:08PM -0500, Putney, Jeff wrote:
> 
> 
> This would seem to work.

Thanks, it did --- on my test case. However, I just noticed
the difference between the test case I posted and my real-world case...
in the real-world case, the overloaded functions are defined 'static'
inside the template class. Now I present my new test case, in which
I try to take the pointer to an overloaded static member function of a
template class.  The test case simpler, too.

I'm using egcs-2.95 19990629 on Linux 2.2.5 on an i686 machine.

Here's the output from g++ -c test.cpp

$ g++ -c test.cpp
test.cpp: In method `void cb<char,int>::func(char, int)':
test.cpp:50:   instantiated from here
test.cpp:39: initialization to `void (cb<char,int>::*)(void *)' from `void (*)(void *)'
test.cpp:42: no matches converting function `overloaded_non_template' to type `void (cb<char,int>::*)(int)'
test.cpp:12: candidates are: static void cb<char,int>::overloaded_non_template(int)
test.cpp:13:                 static void cb<char,int>::overloaded_non_template(void *)
test.cpp:43: no matches converting function `overloaded_template' to type `void (cb<char,int>::*)(char, int)
test.cpp:14: candidates are: static void cb<char,int>::overloaded_template(char, int)
test.cpp:15:                 static void cb<char,int>::overloaded_template(char, void *)
test.cpp:44: no matches converting function `overloaded_template_2' to type `void (cb<char,int>::*)(int, cb<char,int> *)'
test.cpp:16: candidates are: static void cb<char,int>::overloaded_template_2(int, cb<char,int> *)
test.cpp:17:                 static void cb<char,int>::overloaded_template_2(cb<char,int> *, cb<char,int> *)

And attached is test.cpp.

I'm not sure if taking a pointer to a static member function of a template
class is legal or not.  This type of code does work with gcc
(2.5.8... don't ask why), MSVC, and IBM VisualAge C++ (OS/2).

thanks for any help,

--gilbert
/* --------------------------- Class One */
template<class T, class K>
class cb {
        public:
                cb(T, K);

        T       val;
        K       val2;
        void    *f;

        static void    not_overloaded(void*) { };
        static void    overloaded_non_template(int) { };
        static void    overloaded_non_template(void*) { };
        static void    overloaded_template(T, int) { };
        static void    overloaded_template(T, void*) { };
        static void    overloaded_template_2(K, cb<T,K>*) { };
        static void    overloaded_template_2(cb<T,K>*, cb<T,K>*) { };

        void    func(T, int);
};

template<class T, class K>
cb<T,K>::cb(T a, K b)
{
        val = a;
	val2 = b;
}


/* ======================================================*/
/* Here I try to get a pointer to an overloaded */
/* function whose argument is a template class argument */
/* ======================================================*/

template<class T, class K>
void cb<T, K>::func(T a, int n)
{
        /* works, with warning */
        void (cb<T,K>::* ptr_not_overloaded)(void*) = &cb<T,K>::not_overloaded;

        /* these three fail */
        void (cb<T,K>::* ptr_overloaded_non_template)(int) = &cb<T,K>::overloaded_non_template;
        void (cb<T,K>::* ptr_overloaded_template)(T, int) = &cb<T,K>::overloaded_template;
        void (cb<T,K>::* ptr_overloaded_template_2)(K, cb<T,K>*) = &cb<T,K>::overloaded_template_2;

        val = a;

}

template cb<char, int>;

/* ------------------------------ */



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]