problem with Koenig lookup ?

From: Bronek Kozicki <brok_at_rubikon.pl>
Date: 21 Sep 2003 14:54:37 -0400


following snippet has been recently posted on pl.comp.lang.c :
1	template <typename T>
2	struct A
3	{
4		friend void f(A<T>&) { }
5	};
6	
7	template <typename T>
8	struct P
9	{
10		P()
11		{
12			t_ = new T();
13		}
14	
15		~P()
16		{
17			f(*t_);
18		}
19	
20		T * t_;
21	};
22	
23	int main()
24	{
25		P< A<int> > p;
26	}

It compiles sucesfully on GCC 3.2.3 and MSVC71. However, after commenting out line 12 both compilers are throwing error:

(MSVC71)

C:\WINGNU\msys\1.0\home\bronislaw\T93.cpp(17) : error C3861: 'f': identifier not found, even with argument-dependent lookup

        C:\WINGNU\msys\1.0\home\bronislaw\T93.cpp(16) : while compiling class-template member function 'P<T>::~P(void)'

        with
        [
            T=A<int>
        ]
        C:\WINGNU\msys\1.0\home\bronislaw\T93.cpp(25) : see reference to
class template instantiation 'P<T>' being compiled
        with
        [
            T=A<int>
        ]

(GCC 3.2.3)

C:/WINGNU/msys/1.0/home/bronislaw/T93.cpp: In destructor `P<T>::~P() [with T =

   A<int>]':
C:/WINGNU/msys/1.0/home/bronislaw/T93.cpp:25: instantiated from here C:/WINGNU/msys/1.0/home/bronislaw/T93.cpp:17: `f' undeclared (first use this

   function)
C:/WINGNU/msys/1.0/home/bronislaw/T93.cpp:17: (Each undeclared identifier is

   reported only once for each function it appears in.)

I think that code is fine (Comeau compiles it sucesfully), and error is due to incomplete Koenig lookup. Or am I wrong ?

B.  

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
Received on Sun Sep 21 2003 - 11:54:37 PDT

Click to report inappropriate content