473,566 Members | 3,004 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

using and de-referencing a function pointer in a member function

Hi everyone,

I'm trying to execute the same function call with 1 parameter different
in a switch statement of a member function. However, if a certain
condition is true (and I can check that before the switch statement), I
want to execute a difference function call with the same parameters.

So instead of using an if-clause to distinguish the 2 cases in each
case-statement, or doubling the switch, I considered this:

void configuration:: add (string param, configParameter cp);
void configuration:: set (string param, configParameter cp);

my member function:

void configuration:: add (string param, string strType, string strValue);
{
void (configuration: :*add_or_set)(s tring, configParameter );

if (/* my condition */) add_or_set = &configuration: :add;
else add_or_set = &configuration: :set;

/* then the switch statement */
switch (expression) {
case a: (this->*add_or_set) (someString, someConfigParam eter);
break;
case b: (this->*add_or_set) (someOtherStrin g, someConfigParam eter);
break;
default:
break;
}
}

After I played around with the de-referencing for a bit, getting various
error messages, I finally got it right (seemingly) with this expression
(this->*add_or_set) (parameters ...)

So my question: Is this the way to go? Or should I use a different
syntax? Thank you in advance!

Lars
Jun 27 '08 #1
6 1182
Lars Uffmann wrote:
Hi everyone,

I'm trying to execute the same function call with 1 parameter different
in a switch statement of a member function. However, if a certain
condition is true (and I can check that before the switch statement), I
want to execute a difference function call with the same parameters.

So instead of using an if-clause to distinguish the 2 cases in each
case-statement, or doubling the switch, I considered this:

void configuration:: add (string param, configParameter cp);
void configuration:: set (string param, configParameter cp);

my member function:

void configuration:: add (string param, string strType, string strValue);
{
void (configuration: :*add_or_set)(s tring, configParameter );

if (/* my condition */) add_or_set = &configuration: :add;
else add_or_set = &configuration: :set;

/* then the switch statement */
switch (expression) {
case a: (this->*add_or_set) (someString, someConfigParam eter);
break;
case b: (this->*add_or_set) (someOtherStrin g, someConfigParam eter);
break;
default:
break;
}
}

After I played around with the de-referencing for a bit, getting various
error messages, I finally got it right (seemingly) with this expression
(this->*add_or_set) (parameters ...)

So my question: Is this the way to go? Or should I use a different
syntax? Thank you in advance!
Yes, it's the only syntax available to you directly. You can, of
course, declare a 'configuration& ' and init it by *this, but you will
still have to use the parens:

configuration& self = *this;
...
case a: (self.*add_or_s et)(someString, someConfigParam eter);

Now, let me be the first to note that you should probably pass those
strings by reference to const...

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jun 27 '08 #2
Victor Bazarov wrote:
Lars Uffmann wrote:
>So my question: Is this the way to go? Or should I use a different
syntax? Thank you in advance!
Yes, it's the only syntax available to you directly. You can, of
course, declare a 'configuration& ' and init it by *this, but you will
still have to use the parens:
Thank you!

>void configuration:: add (string param, configParameter cp);
[..]
case a: (self.*add_or_s et)(someString, someConfigParam eter);
Now, let me be the first to note that you should probably pass those
strings by reference to const...
Hmmm - I'm not really using by reference to const parameters at all yet
- are you only talking about a way to save computing time by evading a
copy construction of a new string? Or is there something else involved?

Best Regards,

Lars
Jun 27 '08 #3
Lars Uffmann wrote:
Victor Bazarov wrote:
>Lars Uffmann wrote:
>>So my question: Is this the way to go? Or should I use a different
syntax? Thank you in advance!
Yes, it's the only syntax available to you directly. You can, of
course, declare a 'configuration& ' and init it by *this, but you will
still have to use the parens:

Thank you!

>>void configuration:: add (string param, configParameter cp);
[..]
case a: (self.*add_or_s et)(someString, someConfigParam eter);
Now, let me be the first to note that you should probably pass those
strings by reference to const...

Hmmm - I'm not really using by reference to const parameters at all yet
Why?
- are you only talking about a way to save computing time by evading a
copy construction of a new string? Or is there something else involved?
Uh... Yeah... I am talking about the choice you had

void foo(string blah)

versus

void foo(string const& blah)

which is a bit better (generally speaking). When you can avoid making a
copy, you should.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jun 27 '08 #4
Victor Bazarov wrote:
>Hmmm - I'm not really using by reference to const parameters at all yet
Why?
Because there is a bazillion aspects to learn about a programming
language, and learning by doing you only learn stuff as you need it or
read about it. I simply didn't need it yet (since 1993ish, but then I
did a lot in other languages over the years) and wasn't worried about
the speed issue here, but as you can see:
>- are you only talking about a way to save computing time by evading a
copy construction of a new string? Or is there something else involved?
Uh... Yeah... I am talking about the choice you had
[..]
which is a bit better (generally speaking). When you can avoid making a
copy, you should.
I was able to make an educated guess at your comments purpose, and will
be using this in the future, if applicable.
Best Regards,

Lars
Jun 27 '08 #5
my question: What Is the way to go on PHP Programming?
Jul 2 '08 #6
Ro******@gmail. com wrote:
my question: What Is the way to go on PHP Programming?
A good start would be finding a forum where PHP is topical.
Best

Kai-Uwe Bux
Jul 2 '08 #7

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

Similar topics

0
5594
by: Mike | last post by:
Sites using thumbnail preview for world wide web file navigation and searching. Below are list of sites that are either researching or providing thumbnail preview images for online web documents. Thumbnail previews are useful for web site navigation particularly in search engines and directories such as Google, Altavista and Yahoo. The...
1
1607
by: marcum williams | last post by:
Finding absolutely no documentation for updating existing projects on a remote server using Web Setup Projects. Any help would be much appreciated. thanks
1
359
by: Cindy | last post by:
I'm trying to create a satellite assembly for my winform project but the resource.dll that gets created with the assembly linker (al.exe) doesn't get used when the language is specified. However, if I create the satellite assembly in VS by compiling the project with the the translated .resx file, then the resource.dll is used. My project...
8
4917
by: nbaiju | last post by:
Hi, I am building a asp.net application which has satellite assemblies. When building the satellite assemblies dll's from Visual Studio 2003 GUI the application works fine . i.e. the resource dll's of different cultures are loaded correctly. But When I build the satellite assemblies dll's using al.exe the application defaults to the culture...
10
9845
by: Fabrizio | last post by:
(Sorry for the crosspost, but I really don't know which is the right newsgroup!) Hi all, I try to change the password to a user that as to change the password at first logon: try {
5
1527
by: Rich | last post by:
I loaded visual studio.Net 2003 on a windows XP workstation, and I was able to run aspx applications. Later I loaded JBuilder 2005 (Enterprise Java builder 2005) which runs the Tomcat 5.0 web server (and some other servers - for RMI, application servers). I was still able to run vb.net and C# apps in vs2003. Then, yesterday (Thurs May 12,...
4
3497
by: razvan | last post by:
I need advice about adding security to a web service without using WSE, as the clients will run Win98.
5
3784
by: AliR | last post by:
Hi Everyone, I have a Visual C++ MFC program, and I am trying to use a webservice written in C#. When I add the webservice to my project using Add Web Reference the sproxy compiler complains about one of the object wanting to extend MarshalByRefObject object, and I get an error SDL1030. I can use the webservice in a C# project just fine...
15
21453
by: Ms Rusty Boyd | last post by:
I am working in MS Access 2003 and I want to use the update query to change part of a value in a field. I have a last name field that contains a lot of records. Someone entered the values De Pedro and De La Rosa etc. and my boss wants them in lower case de Pedro and de la Rosa. I want to update De to de without having to manually change them. I...
0
1640
by: ajorge | last post by:
I'm a rookie with C# and VB programming languages, but I need to make a connection of two GSM Modems for Remote Monitoring. I've done some web research and i've found a C# code to make the two modems dialing. I converted that code to VB but something's wrong... When i run the program, there's an error and i can't find it's origins. Could someone...
0
7673
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7584
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8109
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7645
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7953
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5485
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3643
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2085
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
926
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.