473,383 Members | 1,892 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Member function selection based on cv qualification

Hello all,

Please see the question in comment form in the program below.

Thanks!
Dave
#include <iostream>

using namespace std;

class foo_t
{
public:
void mem_fun()
{
cout << "No cv qualifications" << endl;
}

void mem_fun() const
{
cout << "const" << endl;
}

void mem_fun() volatile
{
cout << "volatile" << endl;
}

void mem_fun() const volatile
{
cout << "const volatile" << endl;
}
};

int main()
{
foo_t foo;

// How does the compiler decide which member function the initializer
// below references? This is well-formed!
void (foo_t::* ptr)() = &foo_t::mem_fun;

(foo.*ptr)();
}
Jul 22 '05 #1
1 1565
Dave wrote:
#include <iostream>

using namespace std;

class foo_t
{
public:
void mem_fun()
{
cout << "No cv qualifications" << endl;
}

void mem_fun() const
{
cout << "const" << endl;
}

void mem_fun() volatile
{
cout << "volatile" << endl;
}

void mem_fun() const volatile
{
cout << "const volatile" << endl;
}
};

int main()
{
foo_t foo;

// How does the compiler decide which member function the initializer
// below references? This is well-formed!
void (foo_t::* ptr)() = &foo_t::mem_fun;

(foo.*ptr)();
}


AFAIK, the type of the pointer to which the pointer to overloaded function
is assigned participates in the decision making. Since 'ptr' type doesn't
include any qualifiers, the unqualified function is used. Change your
program to be

...
int main()
{
foo_t foo;
void (foo_t::*ptr)() const = &foo_t::mem_fun;
(foo.*ptr)();
}

and you will see the difference.

Victor
Jul 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: joe | last post by:
hi, after reading some articles and faq, i want to clarify myself what's correct(conform to standard) and what's not? or what should be correct but it isn't simply because compilers don't...
39
by: JKop | last post by:
Back when I read my first C++ book, I was given the following scenario: class Cheese { public: int number_of_holes; int colour;
4
by: Tom | last post by:
Let's say I've got a class defined in a header file. class foo { private: ... int bar; .... }; Now lets say I have a function that needs to access the private variable
4
by: Lionel B | last post by:
Greetings, The following code: <code> template<typename T> class A { protected:
6
by: Bill Rubin | last post by:
The following code snippet shows that VC++ 7.1 correctly compiles a static member function invocation from an Unrelated class, since this static member function is public. I expected to compile the...
6
by: cbull | last post by:
class A { }; class B: public A { void f(); }; typedef void (A::*MPA)(void); MPA mpA;
5
by: Gianni Mariani | last post by:
I'm hoping someone can tell me why using member address of works and why using the dot operator does not in the code below. The code below uses the template function resolution mechanism to...
7
by: WaterWalk | last post by:
Hello. I thought I understood member function pointers, but in fact I don't. Consider the following example: class Base { public: virtual ~Base() {} }; class Derived : public Base {
31
by: huili80 | last post by:
Say I have two classes: class A { public: int x; }; class B {
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.