473,811 Members | 3,424 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Clarification - Pointer to Function ..

Consider a number of instances of template class
vector<a>, vector<b> ..., vector<f>
The types are - of course different. Of interest is an efficient way
to access them at runtime.

One approach.

if ( condition A is satisfied )
use vector<a>

Presumably some 'relevant pattern' would be ideal compared to a chain
of if's in all related methods.

So in an email I received, I'm told - advisors are great creatures -
to create a heterogeneous container. I've included 'enough' of the
example for traceability.
The example

template<class T>
class Proxy0
{
public:
typedef T TYPE_R;
virtual T CallFunc()=0;
};

//////////////////////////////////////
// Create a Heterogeneous Container
template<typena me I, typename T, typename F>
class HetContainer_Co mmonFunction0 : public I
{
public:
HetContainer_Co mmonFunction0(T *Src, F f) : TargetClass(Src ),
m_f(f){}
I::TYPE_R CallFunc()
{
return ((*TargetClass) .*m_f)();
}
~HetContainer_C ommonFunction0( ) { delete TargetClass; }
T *TargetClass;
F m_f;
};

template<typena me R, typename T, typename F>
Proxy0<R>* CreateHeterogen eousContainer(T * Src, F f)
{
return new HetContainer_Co mmonFunction0<P roxy0<R>,T, F>(Src, f);
}
// more

At issue is the call
return ((*TargetClass) .*m_f)();

I realize it's a function pointer call, however, the member access
specifier . coupled with the deference operator * for m_f makes the
syntax very confusing to me.

Thanks for your time
Jul 22 '05 #1
5 1482
Uh, we don't do homework here.

Although your advisor's ideas and coding style leaves much to be desired.

If you have some more specific problem, do post again with concrete
code (preferably self-describing names also!) illustrating the problem.

* ma740988:
Consider a number of instances of template class
vector<a>, vector<b> ..., vector<f>
The types are - of course different. Of interest is an efficient way
to access them at runtime.

One approach.

if ( condition A is satisfied )
use vector<a>

Presumably some 'relevant pattern' would be ideal compared to a chain
of if's in all related methods.

So in an email I received, I'm told - advisors are great creatures -
to create a heterogeneous container. I've included 'enough' of the
example for traceability.
The example

template<class T>
class Proxy0
{
public:
typedef T TYPE_R;
virtual T CallFunc()=0;
};

//////////////////////////////////////
// Create a Heterogeneous Container
template<typena me I, typename T, typename F>
class HetContainer_Co mmonFunction0 : public I
{
public:
HetContainer_Co mmonFunction0(T *Src, F f) : TargetClass(Src ),
m_f(f){}
I::TYPE_R CallFunc()
{
return ((*TargetClass) .*m_f)();
}
~HetContainer_C ommonFunction0( ) { delete TargetClass; }
T *TargetClass;
F m_f;
};

template<typena me R, typename T, typename F>
Proxy0<R>* CreateHeterogen eousContainer(T * Src, F f)
{
return new HetContainer_Co mmonFunction0<P roxy0<R>,T, F>(Src, f);
}
// more

At issue is the call
return ((*TargetClass) .*m_f)();

I realize it's a function pointer call, however, the member access
specifier . coupled with the deference operator * for m_f makes the
syntax very confusing to me.

Thanks for your time


--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 22 '05 #2
al***@start.no (Alf P. Steinbach) wrote in message news:<41******* ********@news.i ndividual.net>. ..
Uh, we don't do homework here.
How you attribute my request to homework assistance is beyond me.

Although your advisor's ideas and coding style leaves much to be desired.

If you have some more specific problem, do post again with concrete
code (preferably self-describing names also!) illustrating the problem.

It's simple: I was following the source example emailed to me until I
ran across this sytax: "return ((*TargetClass) .*m_f)();" I realize
it's a pointer to a function, however, this portion '.*m_f' makes no
sense to me.
Jul 22 '05 #3
ma740988 wrote in news:a5******** *************** **@posting.goog le.com in
comp.lang.c++:
At issue is the call
return ((*TargetClass) .*m_f)();

I realize it's a function pointer call, however, the member access
specifier . coupled with the deference operator * for m_f makes the
syntax very confusing to me.


There is no "coupling" above only the ".*" operator.

The operator ".*" ( and "->*" ) are for accessing via a member-pointer:

#include <iostream>

struct X
{
int f() { std::cout << "f()\n"; return 0; }
int g() { std::cout << "g()\n"; return 1; }
};

void test( X &x, int (X::*mf)() )
{
int i = (x.*mf)();
std::cout << "test: " << i << '\n';
}

template < typename T, typename F >
void test2( T *x, F f )
{
int i = (x->*f)();
std::cout << "test2: " << i << '\n';
}

int main()
{
X x;

test( x, &X::f );

test2< X, int (X::*)() >( &x, &X::g );

std::cout.flush ();
}

Note the explicit template arguments in the call of test2() above
aren't needed here, but you will need them to instantiate a
class template.

Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jul 22 '05 #4
ma740988 wrote:

al***@start.no (Alf P. Steinbach) wrote in message news:<41******* ********@news.i ndividual.net>. ..
Uh, we don't do homework here.

How you attribute my request to homework assistance is beyond me.
Although your advisor's ideas and coding style leaves much to be desired.

If you have some more specific problem, do post again with concrete
code (preferably self-describing names also!) illustrating the problem.

It's simple: I was following the source example emailed to me until I
ran across this sytax: "return ((*TargetClass) .*m_f)();" I realize
it's a pointer to a function, however, this portion '.*m_f' makes no
sense to me.


..* is a seperate operator in C++.
It is the 'pointer to member' operator.

The intent in your case seems to be to return a pointer to a member function.

--
Karl Heinz Buchegger
kb******@gascad .at
Jul 22 '05 #5
Rob Williscroft <rt*@freenet.co .uk> wrote in message news:<Xn******* *************** ************@13 0.133.1.4>...
ma740988 wrote in news:a5******** *************** **@posting.goog le.com in
comp.lang.c++:
At issue is the call
return ((*TargetClass) .*m_f)();

I realize it's a function pointer call, however, the member access
specifier . coupled with the deference operator * for m_f makes the
syntax very confusing to me.


There is no "coupling" above only the ".*" operator.

The operator ".*" ( and "->*" ) are for accessing via a member-pointer:

#include <iostream>

struct X
{
int f() { std::cout << "f()\n"; return 0; }
int g() { std::cout << "g()\n"; return 1; }
};

void test( X &x, int (X::*mf)() )
{
int i = (x.*mf)();
std::cout << "test: " << i << '\n';
}

template < typename T, typename F >
void test2( T *x, F f )
{
int i = (x->*f)();
std::cout << "test2: " << i << '\n';
}

int main()
{
X x;

test( x, &X::f );

test2< X, int (X::*)() >( &x, &X::g );

std::cout.flush ();
}

Note the explicit template arguments in the call of test2() above
aren't needed here, but you will need them to instantiate a
class template.

Excellent. Thanks to both you and Karl.
Jul 22 '05 #6

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

Similar topics

5
6088
by: Sir_Ciph3r | last post by:
Can someone explain what is happening in the following code? #include <iostream> #include <vector> #include <map> using namespace std; int main() {
4
2896
by: Shea Martin | last post by:
Which of the following do I use delete instead of just delete. //1.) // not sure about this one, as char is of size 1 char *str = new char; //2.) //not sure about this one, as it is a primitive int *array = new int;
3
1420
by: ma740988 | last post by:
Consider the 'C' source. void myDoorBellISR(starLinkDevice *slDevice, U32 doorBellVal) { doorBellDetected = doorBellVal; } void slRcv() { starLinkOpenStruct myOpenStruct;
11
1794
by: Achintya | last post by:
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& #include<iostream> using namespace std; class A { int i; virtual void f(){ cout<<endl<<"i= "<<i; } public: A(int j) { i = j; }
3
2353
by: Karthik D | last post by:
Hello All, Basically I would like to take suggestions from programmers about implementation of a function which processes some error messages.(fyi:this is not a homework problem) Let me explain my problem in detail.I have a function which closely emulates dlerror() function. The function is as below: void dlerror(void *handle, char *err, size_t len) {
4
1873
by: chanchito_cojones | last post by:
Hi there, I was searching the net for some guidance in putting together a query that would select random records from the main table. I came across this and it works like a charm. SELECT TOP 5 * FROM tablename ORDER BY Rnd(IsNull(fieldname)*0+1);
2
1129
by: Workgroups | last post by:
I need some clarification with the whole "no pointers in VB.NET" thing, because it seems like there are "quazi-pointers" happening but I want to make sure I'm interpreting all this correctly. Here's a generic class declaration for the sake of example: Public clsClass 'properties, methods End Class
2
1722
by: subramanian100in | last post by:
Consider the following program: #include <stdio.h> void myfn(const int **a) { static int i, j, k; a = &i; a = &j;
2
1360
by: manjuks | last post by:
Hi All, Assume we have allocated 100 bytes of memory using malloc, We will get a pointer to the allocated memory, to free up this memory we will pass this pointer to free function. My question is how free will come to know that it needs to free 100 bytes of memory? where it gets this information? Thanks, Manjunath
0
9730
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10651
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10392
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10403
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
9208
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6893
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5555
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5693
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3868
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.