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 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;
};
"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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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
|
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++)
{
|
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.
|
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...
|
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 *)
| |
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...
|
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...
|
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>
|
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,...
|
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...
|
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,...
| |
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...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |