473,883 Members | 1,570 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

template <typename T> struct polymorphic : public T ???

Last week I asked here how I could detect that a T was polymorphic, and
received
very thoughtful and useful replies that I used straight away. Thanks to all who
answered.

This week, it turns out that detecting whether T is polymorphic clashes with
a new requirement, that T be allowed to not be complete.

Last week, this code used to compile:

typedef std::queue<Requ est> RequestQueue ;
typedef envelope<Reques tQueue> Queue ;

This week, I now have to wrap std::queue into a polymorphic
container, as in:

struct RequestQueue : public std::queue<Requ est> {
// envelope does NOT work with monomorphic types
virtual ~RequestQueue() {} ;
} ;

typedef envelope<Reques tQueue> Queue ;

Obviously, I'd like to create some kind of adaptor template ...

template <typename T> struct polymorphic : public T {
virtual ~polymorhic() {}
} ;

intended usage:

typedef polymorphic<std ::queue<int> > Queue ;

But this doesn't compile!

The FAQ#35 seems mute here, and I'm beginning to suspect that
something is wrong with my syntax. I also checked
http://www.boost.org/libs/utility/call_traits.htm &
http://www.boost.org/libs/conversion/cast.htm (because it
contained the word: polymorphic_cas t, but this turned out
a red-herring)

What would be the correct way to do this?

Many thanks, again.

--
JFB

Jul 23 '05 #1
1 2266
On 2005-06-25 16:55:32 +0100, verec <ve***@mac.co m> said:
struct RequestQueue : public std::queue<Requ est> {
// envelope does NOT work with monomorphic types
virtual ~RequestQueue() {} ;
} ;

typedef envelope<Reques tQueue> Queue ;

Obviously, I'd like to create some kind of adaptor template ...

template <typename T> struct polymorphic : public T {
virtual ~polymorhic() {}
} ;


I'm not sure exactly what went wrong, but this first version
was correct ...

#include <iostream>
#include <string>
#include <queue>
template <typename T> struct polymorphic : public T {
virtual ~polymorphic() {}
} ;

void
test_00001() {
typedef polymorphic<std ::queue<int> > IntQueue ;

IntQueue queue ;

queue.push(5) ;
queue.push(6) ;
queue.push(7) ;
queue.push(8) ;

while(!queue.em pty()) {
int i = queue.front() ;
queue.pop() ;
std::cout << "Just popped: " << i << std::endl ;
}
}

Though I couldn't find a single example of use that particular
syntax (which kind of turns templates inside out) it is
accepted by gcc 4.
--
JFB

Jul 23 '05 #2

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

Similar topics

0
1815
by: kyo | last post by:
class A { public: int a; }; struct testfun1 : public unary_function<const A&, bool> { bool operator()(const A &) const {
11
5164
by: Scott Brady Drummonds | last post by:
Hi, everyone, I've checked a couple of on-line resources and am unable to determine how reinterpret_cast<> is different from static_cast<>. They both seem to perform a compile-time casting of one type to another. However, I'm certain that there is something else that is happening. Can someone explain the difference or recommend an online site that can explain it to me?
3
2403
by: Eric Lilja | last post by:
Hello, I was working on a program where I needed to take a vector storing objects of type std::string and convert each object to an int and store the ints in another vector. I decided that I should create a templated function for this because I've done similar things before and expect to do similar things again (i.e., converting a collection of one type to a collection of another type). This is my test program, it compiles but if I try to...
1
1839
by: ma740988 | last post by:
I'm wading my way through Josuttis template text. I'm having a hard time understanding some things. So given: template <class T> class generic_traits { public: typedef T value_type; }; template <class T> class vector_traits {
4
2323
by: Grizlyk | last post by:
Hello. Why were base class "typedefs" hidden by template<and explicit usage of them does not work too? Try open only one of the lines in the example below //using Tparent::Tptr; //typedef Tparent::Tptr Tptr; Consider example:
3
3400
by: ajay2552 | last post by:
Hi, I have a query. All html tags start with < and end with >. Suppose i want to display either '<' or '>' or say some text like '<Company>' in html how do i do it? One method is to use &lt, &gt ,&ltCompany&gt to display '<', '>' and '<Company>' respectively. But is there any freeware code available which could implement the above functionality without having to use &gt,&lt and such stuff???
45
18946
by: Zytan | last post by:
This returns the following error: "Cannot modify the return value of 'System.Collections.Generic.List<MyStruct>.this' because it is not a variable" and I have no idea why! Do lists return copies of their elements? Why can't I change the element itself? class Program { private struct MyStruct
10
3565
by: jason.cipriani | last post by:
Is there any difference between declaring a template parameter as a "typename" or a "class"? E.g. template <class TT f() { } template <typename TT g() { } Thanks, Jason
5
17700
RRick
by: RRick | last post by:
I have a simple template method that looks like template < typename T> void WhatEver( void) { T t; // How to print with cout the T value (not the t value)? } I thought maybe RTTI would work, but that deals with classes with virtual methods. Since T is most likely going to be an int or double, is there any built in C++ way to print out the value of T.
0
9793
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
10750
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
10858
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
10419
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
9577
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...
1
7974
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5804
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
5996
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4619
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 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.