473,788 Members | 2,811 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

visitor woe

Hi,

I am trying to create a framework, that automatically generates a base
class for the visitor pattern:

template <typename param, typename ret = void>
struct visitor
{
typedef ret return_type;
virtual return_type visit(param *) = 0;
};

template <class head, class tail, typename ret>
struct visitor<type_co ns<head, tail>, ret>
: public visitor<head, ret>, public visitor<tail, ret>
{ typedef ret return_type; };

template <class head, typename ret>
struct visitor<type_co ns<head, null_type>, ret>
: public visitor<head, ret>
{ typedef ret return_type; };

But if I instantiate this type with

typedef make_typelist<u nsigned, long double, string>::result tlist;
typedef visitor<tlist, void> visit;

and use it via

void accept (visit &vis)
{
unsigned u = 1;
vis.visit(&u);
}

gcc says:

In function `void accept(visit&)' :
error: request for member `visit' is ambiguous
error: candidates are: ret visitor<param, ret>::visit(par am*) [with param = std::string, ret = void]
error: ret visitor<param, ret>::visit(par am*) [with param = long double, ret = void]
error: ret visitor<param, ret>::visit(par am*) [with param = unsigned int, ret = void]

I am totaly out of ideas how to persuade gcc to choose the one that
expects an unsigned * for parameter. Any ideas?

Thx

ImRe

P.S.: gcc -dumpversion 3.4.0
Nov 23 '05 #1
2 1488

Imre Palik wrote:

[]

The problem you are experiencing is caused by name hiding, you might
like to google for it.

The fix is easy:
template <class head, class tail, typename ret>
struct visitor<type_co ns<head, tail>, ret>
: public visitor<head, ret>, public visitor<tail, ret> {
using visitor<head, ret>::visit;
using visitor<tail, ret>::visit;
typedef ret return_type;
};
template <class head, typename ret>
struct visitor<type_co ns<head, null_type>, ret>
: public visitor<head, ret>

{
using visitor<head, ret>::visit;
typedef ret return_type;
};

Nov 23 '05 #2
"Maxim Yegorushkin" <ma************ ***@gmail.com> writes:
Imre Palik wrote:

[]

The problem you are experiencing is caused by name hiding, you might
like to google for it.


Thanks
Nov 23 '05 #3

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

Similar topics

2
1505
by: Lars Tackmann | last post by:
Hi I have a problem where i have allocated an array on the heap, using new in a class called "Array". In the end of my main i call a visit method that visits all of the elements in class "Array" using a visitor object eg. // visits each element in the list
2
2359
by: Wavemaker | last post by:
I've been playing with C# v2.0 today, and having quite a bit of fun. The new version has added iterators. The iterators are coded directly into the class to be iterated. For example: public IEnumerable<int> Visit(SomeVisitor visitor) { int position = 0; for(int i = 0; i < Count; i++) {
12
3040
by: FluffyCat | last post by:
New on November 28, 2005 for www.FluffyCat.com PHP 5 Design Pattern Examples - the Visitor Pattern. In the Visitor pattern, one class calls a function in another class and passes an instance of itself. The called class has special functions for each class that can call it. With the visitor pattern, the calling class can have new operations added without being changed itself.
17
2609
by: Merlin | last post by:
Probably there is no right or wrong answer to this but I thought to ask to put my mind at rest. Ok lets say you have a object hierarchy (eg. the Glyph in Lexi from GOF book) and you want to use the visitor pattern. So we place an accept method in the the base class glyph and procede to create the visitor hierarchy. The accept signature will look like this void Glyph::Accept(Visitor& v); The Visitor hierarchy will have a Vistor base...
0
1919
by: Siphiuel | last post by:
Hi everyone. When using visitor pattern, we have a nasty dependence on the types of visitable objects that is coded way on top on the visitor hierarchy. i mean, like this: class AbstractVisitor { public: virtual void visit(Object_type_1 *); virtual void visit(Object_type_2 *)
1
6527
by: JosAH | last post by:
Greetings, this week we let go of all that algebraic stuff and concentrate a bit more on what object oriented programming is all about. Java claims to support OO, so why not use it? In this week's article we're going to talk a bit about when and why to apply certain patterns. We'll start with the Visitor pattern. The pattern is also named 'double dispatch' which will become clear near the end of this little article. Here's the...
0
11630
weaknessforcats
by: weaknessforcats | last post by:
Design Patterns: Visitor Introduction Polymorphism requires a class hierarchy where the interface to the hierarchy is in the base class. Virtual functions allow derived classes to override base class functions. Applications using polymorphism typically have functions with base class pointers or references as arguments. Then derived objects are created and used as arguments to these functions. Inside the function, only the base class methods...
3
2314
by: aaragon | last post by:
Hello everyone, I've been trying to work with the visitor design pattern, and it works fine except for the following. Let's suppose that we have a fixed hierarchy of classes (many of them) which I cannot modify. I decided to use the visitor design pattern depending on the actual type of the classes because those classes already support the loki visitor. #include <Loki/Visitor.h>
0
9498
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10370
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...
1
10113
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
9969
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6750
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
5538
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4074
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
2
3677
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2896
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.