473,320 Members | 1,870 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,320 software developers and data experts.

Scope resolution in needed to call a functor maker

/*
I don't have to provide scope resolution in sit 0 below: adl
finds the function that I mean to use.

I do have to provide scope resolution in sits 1 and 2.

Can anyone teach me a trick to get around the need for scope resolution
in sit 1 or sit 2?

sit 1 is my motivating case, but if there's a trick for sit 2 I'd like
to know it too.
*/

#include <iostream>
using namespace std;

// minimalist functor
template < typename xCallable, typename xResult >
struct ftor
{
typedef xCallable tCallable;
typedef xResult tResult;
ftor(const ftor & fThat):cCallable(fThat.cCallable){}
explicit ftor(tCallable fCallable):cCallable(fCallable){}
template < typename xArg > tResult operator()(xArg fArg) const
{return cCallable(fArg);}
tCallable cCallable;
};

// functor maker
template < typename xResult, typename xArg >
ftor< xResult (*)(xArg), xResult >
make_ftor(xResult (*fPtrFunc)(xArg))
{return ftor< xResult (*)(xArg), xResult >(fPtrFunc);}

// class and function that uses it
namespace A
{
class a{};
a func(a fA){cout << "::A::func" << endl; return fA;}
}

int main()
{
typedef A::a tA;
typedef tA (*tPtrFunc)(tA);

tA fA;

// sit 0 - Finds through adl
func(fA);

// sit 1 - Insists on scope resolution
make_ftor(A::func)(fA);

// sit 2 - Insists on scope resolution
tPtrFunc fPtrFunc = A::func;
fPtrFunc(fA);
}
Jul 23 '05 #1
0 1068

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

Similar topics

5
by: exits funnel | last post by:
Hello, I'm confused by the use of the Scope resolution operator on the indicated lines in the following code (which was copied from Thinking in C++ by Bruce Eckel). Removing them seems to have...
3
by: richard pickworth | last post by:
Hello :) I am familiar with using scope resolution operator to define classes, but why does it turn up elsewhere? thanks richard
8
by: lawrence | last post by:
I'm learning Javascript. I downloaded a script for study. Please tell me how the variable "loop" can have scope in the first function when it is altered in the second function? It is not defined...
6
by: Jack | last post by:
I want to write code that can be compiled as C and C++. In the Windows API, there are many macros that help with scope resolution. For example: #ifdef __cplusplus #define SNDMSG ::SendMessage...
7
by: John Salerno | last post by:
I have the following code: class DataAccessFrame(wx.Frame): menu_items = def __init__(self): wx.Frame.__init__(self, None, title='Database Access Panel')
1
by: beagleears | last post by:
I have a piece of code in which I pass a function to a function and it works fine in stand alone code but when I encorporate it in a class my compiler tells me there is no matching function. The...
3
by: toton | last post by:
Hi, Is it possible to have a class level namespace opening instead of file level . Something like this, I have a long namespace like namespace com { namespace my_company{ namespace...
3
by: =?Utf-8?B?Sm9uYXRoYW4gU21pdGg=?= | last post by:
I have a class as follows: class GamesConsole { public int iReference; public enum Maker {Nintendo, Sega, Sony, Panasonic} }
2
by: aaragon | last post by:
Hi guys, Is there a way to return a functor from a recursive call that takes different paths? Let's say that I have a tree structure like: root | first child ---- nextSibling ----nextSibling...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.