help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Pointer to function problem


From: Pierre Barbier de Reuille
Subject: Re: Pointer to function problem
Date: Sun, 23 Jul 2006 15:56:58 +0100
User-agent: Thunderbird 1.5.0.4 (X11/20060713)

Pierre Barbier de Reuille wrote:
> Hello,
> 
> I have a problem with g++ 4.1
> I use pointer to functions and I get this error :
> 
> src/wrappers/export_vertex.cpp|122| error: no matches converting
> function 'cross' to type 'real_t (*)(const class TOOLS::Vector2&, const
> class TOOLS::Vector2&)'
> 
> /home/barbier/prog/labo/AMAPmod/src/Tools/util_vector.h|232| error:
> candidates are: real_t TOOLS::cross(const TOOLS::Vector2&, const
> TOOLS::Vector2&)
> 
> /home/barbier/prog/labo/AMAPmod/src/Tools/util_vector.h|510| error:
>             TOOLS::Vector3 TOOLS::cross(const TOOLS::Vector3&, const
> TOOLS::Vector3&)
> 
> 
> Here is the line with the error:
> 
> real_t ( *cv2cv2_cross )( TOOLS::Vector2 const&, TOOLS::Vector2 const& )
> = TOOLS::cross;
> 
> I tried to use a typedef like that :
> 
> typedef real_t ( *r_cv2cv2 )( const Vector2&, const Vector2& );
> r_cv2cv2 cv2cv2_cross = cross;
> 
> But the problem is exactly the same.
> 
> I really don't understand it ! Also, I tried to reproduce the error with
> a simple program but I don't seem to be able to :(
> 
> Thank you,
> 
> Pierre

Ok, I finally found the problem (i.e. I could reproduce it).

The problem seems to be with "friend" functions. The declaration of a
function as friend use to be considered a function declaration, but no
more. Reading the norm, I don't really see why, as it is explicitely
possible to defined entirely a friend function (see 11.4.5):

"""
A function can be defined in a friend declaration of a class if and only
if the class is a non-local class (9.8),
the function name is unqualified, and the function has namespace scope.
[Example:
      class M {
                                                    // definition of
global f, a friend of M,
                 friend void f() { }
                                                    // not the
definition of a member function
      };
 --end example] Such a function is implicitly inline. A friend function
defined in a class is in the
(lexical) scope of the class in which it is defined. A friend function
defined outside the class is not (3.4.1).
"""

Is there any pointer for that question ?

Thanks,

Pierre


reply via email to

[Prev in Thread] Current Thread [Next in Thread]