Test case:
#include <boost/shared_ptr.hpp>
using namespace boost;
template <typename typ1> class cData {
public:
template <typename T> T As() { } // As
};
template <typename D, typename T>
class cTaggedData : public cData<D> {
public:
};
template <typename D, typename T>
class cAttr : public cTaggedData<D,T > {
public:
};
template <typename D, typename T>
class cNode : public cTaggedData<D,T > {
public:
shared_ptr< cAttr<D,T> > RetAttr() { }
template <typename X> X MyAs(T t, X& x) {
#line 100
shared_ptr< cAttr<int,int> > attr1; attr1->As<int>(); // works
#line 200
shared_ptr< cAttr<D,T> > attr2; attr2->As<int>(); // FAILS
#line 300
shared_ptr< cAttr<int,int> > attr3; attr3->As<X>(); // works
#line 400
shared_ptr< cAttr<D,T> > attr4; attr4->As<X>(); // my goal, FAILS
} // As
};
/*
gives:
x.cpp: In member function 'X cNode<D, T>::MyAs(T, X&)':
x.cpp:200: error: expected primary-expression before 'int'
x.cpp:200: error: expected `;' before 'int'
x.cpp:400: error: expected primary-expression before '>' token
x.cpp:400: error: expected primary-expression before ')' token
*/
int main() { }
How to fix thoes two errors? Especially the 400 one? 2 1593
* Rafał Maj Raf256: Test case:
#include <boost/shared_ptr.hpp>
using namespace boost;
template <typename typ1> class cData { public: template <typename T> T As() { } // As };
template <typename D, typename T> class cTaggedData : public cData<D> { public: };
template <typename D, typename T> class cAttr : public cTaggedData<D,T > { public: };
template <typename D, typename T> class cNode : public cTaggedData<D,T > { public:
shared_ptr< cAttr<D,T> > RetAttr() { } template <typename X> X MyAs(T t, X& x) { #line 100 shared_ptr< cAttr<int,int> > attr1; attr1->As<int>(); // works #line 200 shared_ptr< cAttr<D,T> > attr2; attr2->As<int>(); // FAILS #line 300 shared_ptr< cAttr<int,int> > attr3; attr3->As<X>(); // works #line 400 shared_ptr< cAttr<D,T> > attr4; attr4->As<X>(); // my goal, FAILS } // As
}; /* gives:
x.cpp: In member function 'X cNode<D, T>::MyAs(T, X&)': x.cpp:200: error: expected primary-expression before 'int' x.cpp:200: error: expected `;' before 'int' x.cpp:400: error: expected primary-expression before '>' token x.cpp:400: error: expected primary-expression before ')' token */
Using #line is a really good idea, I'll steal that for my own examples!
Anyway,
#line 100
shared_ptr< cAttr<int,int> > attr1; attr1->As<int>(); // works
#line 200
shared_ptr< cAttr<D,T> > attr2; attr2->template As<int>(); // works
#line 300
shared_ptr< cAttr<int,int> > attr3; attr3->As<X>(); // works
#line 400
shared_ptr< cAttr<D,T> > attr4; attr4->template As<X>(); // works
The problem is that you're using the name As which depends on the
template paramters D and T, and the compiler knows nothing about what As
could be (especially, that it would be a template) for any specific D and T.
--
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?
Alf P. Steinbach wrote: Using #line is a really good idea, I'll steal that for my own examples!
Nice :)
#line 100 shared_ptr< cAttr<int,int> > attr1; attr1->As<int>(); // works #line 200 shared_ptr< cAttr<D,T> > attr2; attr2->template As<int>(); // works #line 300 shared_ptr< cAttr<int,int> > attr3; attr3->As<X>(); // works #line 400 shared_ptr< cAttr<D,T> > attr4; attr4->template As<X>(); // works
The problem is that you're using the name As which depends on the template paramters D and T, and the compiler knows nothing about what As could be (especially, that it would be a template) for any specific D and T.
#line 200
shared_ptr< cAttr<D,T> > attr2; attr2->template As<int>();
#line 400
shared_ptr< cAttr<D,T> > attr4; attr4->template As<X>();
is the finall solution then :)
I was quite close, tried to add, in the main class { } cNode scope
using cAttr<D,T>::As< >;
g++ warned me:
note: use 'cAttr<D, T>::template As' to indicate that it is a template
only I put it in wrong place
btw, it seem to compile fine on newer MSVC even without the template
--
Wymiana starych układów... na nowe układy - prawie jak walka z korupcja.
Walka z wychowaniem seksualnym i erotykÄ… - prawie jak walka z patologiÄ….
PiS - prawie jak prawo i sprawiedliwoÅ›Ä ‡... Prawie. Prawie robi różnicÄ™.
Myśl. Głosuj rozsądnie. Nie na tanie hasła. // Rafał Maj Raf256 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: John J. Lee |
last post by:
I'm trying define a class to act as a Mock "handler" object for
testing urllib2.OpenerDirector.
OpenerDirector (actually, my copy of it) does dir(handler.__class__)
to find out what methods a handler supports. So, my mock class has to
have appropriate methods defined on it. To avoid the hassle of
manually defining lots of mock classes, I wanted to have a base class
MockHandler so that I could do
class...
|
by: Leslaw Bieniasz |
last post by:
Cracow, 20.09.2004
Hello,
I need to implement a library containing a hierarchy of classes
together with some binary operations on objects. To fix attention,
let me assume that it is a hierarchy of algebraic matrices with the
addition operation. Thus, I want to have a virtual base class
class Matr;
|
by: Lokkju |
last post by:
I am pretty much lost here - I am trying to create a managed c++
wrapper for this dll, so that I can use it from c#/vb.net, however, it
does not conform to any standard style of coding I have seen. It is
almost like it is trying to implement it's own COM interfaces...
below is the header, and a link to the dll+code:
Zip file with header, example, and DLL:...
|
by: Charles Law |
last post by:
For some reason, when I click the X to close my MDI parent form, the action
appears to be re-directed to one of the MDI child forms, and the parent
remains open. I am then unable to close the application.
What should happen, is that the main MDI form should close, taking the child
forms with it. There is code to loop through the child forms, remove the
controls on each of them, and then close the form, but this code should
execute only...
|
by: graemeharnish |
last post by:
Hello. I'm trying to mod an open source app called TinyERP and inherit
from a parent object, and in essence change how _column is defined. I
found sample code of:
class custom_product(osv.osv):
__inherits__ = "product.product"
__name__ = "product.product"
_columns = {
'color' : fields.many2one('color','Color'),
'size': fields.many2one('size','Size'),
| |
by: ajikoe |
last post by:
Hi,
I tried to follow the example in swig homepage.
I found error which I don't understand.
I use bcc32, I already include directory where my python.h exist in
bcc32.cfg.
/* File : example.c */
#include <time.h>
|
by: TPJ |
last post by:
Help me please, because I really don't get it. I think it's some stupid
mistake I make, but I just can't find it. I have been thinking about it
for three days so far and I still haven't found any solution.
My code can be downloaded from here:
http://www.tprimke.net/konto/PyObject-problem.tar.bz2. There are some
scripts for GNU/Linux system (bash to be precise).
All you need to know is that there are four classes. (Of course, you
may...
|
by: DJG79 |
last post by:
Hi all,
I am using an open source menu that i found and it works great, except
for one thing that when the web page is not scrolled to the very top
the drop down links will not stay visible. Has anyone else had this
sort of problem with javascript? and any ideas how to fix it would be
greatly appreciated..
I have included a copy of the code below, thanks.
/**
|
by: althafexcel |
last post by:
hi everyone
Im trying to include an external js in my aspx page under the head
tag, it doesn't load or it displays an object expected error whenver
the function from the .js is called. Actually for repeated html im
using the external js, i mean the TOP, BOTTOM they are repeated in
every page, so i include them as functions in the external js and call
them. Why it doesn't work?
|
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...
|
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: 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...
|
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: 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...
|
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
| |