This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: why this testcase compile failed for gcc.
- From: Ian Lance Taylor <iant at google dot com>
- To: zhang qingshan <steven dot zhang54373 at gmail dot com>
- Cc: gcc-help <gcc-help at gcc dot gnu dot org>
- Date: Fri, 18 Feb 2011 07:00:18 -0800
- Subject: Re: why this testcase compile failed for gcc.
- References: <AANLkTimvRH-7kexujd8+an6DiD6jXCu5Xj17Hifwnfmg@mail.gmail.com>
zhang qingshan <steven.zhang54373@gmail.com> writes:
> /* ------- test case -------------------*/
> void x();
> template <typename T>
> void foo(const T*);
>
> int main() {
> foo(x);
> }
>
> GCC 4.5 complains:
>
> a.cpp: In function 'int main()':
> a.cpp:6: error: no matching function for call to 'foo(void (&)())'
>
> It seems that, const T * is resolved as void (&)());
>
> IMO, T --> void (), const T --> void (), const T * --> void (*)(), and
> it should be leagle.
You are confusing function pointers with pointers to data objects. They
are not the same thing in C++. That is, a function pointer is not a
special type of pointer.
Ian