type of pointer to member function

T

Tristan Wibberley

Hi all,

What type has the expression &Class::Memberfn in the presence of the
below class definition?

class Class {
public:
void Memberfn();
void Memberfn(int);
};

Is it some anonymous type with implicit conversions to void (Class::*)
() and void (Class::*)(int) ?

In C++0x, what will "auto x = &Class::Memberfn" do?

--
Tristan Wibberley

Any opinion expressed is mine (or else I'm playing devils advocate for
the sake of a good argument). My employer had nothing to do with this
communication.
 
R

red floyd

Tristan said:
Hi all,

What type has the expression &Class::Memberfn in the presence of the
below class definition?

class Class {
public:
void Memberfn();
void Memberfn(int);
};

Is it some anonymous type with implicit conversions to void (Class::*)
() and void (Class::*)(int) ?

In C++0x, what will "auto x = &Class::Memberfn" do?

Probably give a diagnostic complaining about an ambiguous assignment.
 
S

Sebastian Redl

Tristan said:
Hi all,

What type has the expression &Class::Memberfn in the presence of the
below class definition?

class Class {
public:
void Memberfn();
void Memberfn(int);
};

This is the one situation in C++ where the left side of an assignment
decides on the semantics of the right side.

That is, there is no anonymous class as such, but the compiler will look at
the necessary conversion and decide based on that.
 
J

James Kanze

What type has the expression &Class::Memberfn in the presence of the
below class definition?
class Class {
public:
void Memberfn();
void Memberfn(int);
};
Is it some anonymous type with implicit conversions to void
(Class::*) () and void (Class::*)(int) ?

It doesn't have a type, any more than p->Memberfn has a type.
The compiler will apply function overload resolution to it,
according to the context in which it is found. If the compiler
is unable to resolve the overload, it is an error.
In C++0x, what will "auto x = &Class::Memberfn" do?

Probably an error, due to an ambiguous function.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,128
Latest member
ElwoodPhil
Top