473,508 Members | 2,329 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is this possible with a template?

Hello,

I have an application which uses a class called "rSharedPointer". I want to
replace it with the Boost shared pointer but would like to keep the old name
and not modify any existing code.

I have tried doing the following:

typedef boost::shared_ptr<T> rSharedPointer;

and:

template<typename T> typedef boost::shared_ptr<T> rSharedPointer;

But it will not compile?

Any ideas?

Jamie.
Jul 22 '05 #1
3 985
"Jamie Burns" <re************@whatever.com> wrote...
I have an application which uses a class called "rSharedPointer". I want
to replace it with the Boost shared pointer but would like to keep the old
name and not modify any existing code.

I have tried doing the following:

typedef boost::shared_ptr<T> rSharedPointer;

and:

template<typename T> typedef boost::shared_ptr<T> rSharedPointer;

But it will not compile?

Any ideas?


If 'rSharedPointer' is a _class_, you cannot replace it with a template
in your code, the use for classes and templates is different. So, even
if there were (and there isn't) support for template typedefs, how would
you then use your 'rSharedPointer'?

If, contrary to your own words, 'rSharedPointer' is, in fact, a template,
then you could try using a macro:

#define rSharedPointer boost::shared_ptr

V
Jul 22 '05 #2
Thanks Victor.

Yes, it was a template, not a class!

The #define works a treat :o)

Jamie.

"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:6BgBd.594703$wV.391026@attbi_s54...
"Jamie Burns" <re************@whatever.com> wrote...
I have an application which uses a class called "rSharedPointer". I want
to replace it with the Boost shared pointer but would like to keep the
old name and not modify any existing code.

I have tried doing the following:

typedef boost::shared_ptr<T> rSharedPointer;

and:

template<typename T> typedef boost::shared_ptr<T> rSharedPointer;

But it will not compile?

Any ideas?


If 'rSharedPointer' is a _class_, you cannot replace it with a template
in your code, the use for classes and templates is different. So, even
if there were (and there isn't) support for template typedefs, how would
you then use your 'rSharedPointer'?

If, contrary to your own words, 'rSharedPointer' is, in fact, a template,
then you could try using a macro:

#define rSharedPointer boost::shared_ptr

V

Jul 22 '05 #3
Jamie Burns wrote:
...
I have an application which uses a class called "rSharedPointer". I want to
replace it with the Boost shared pointer but would like to keep the old name
and not modify any existing code.

I have tried doing the following:

typedef boost::shared_ptr<T> rSharedPointer;

and:

template<typename T> typedef boost::shared_ptr<T> rSharedPointer;

But it will not compile?

Any ideas?
...


It looks like you need a template 'typedef'. C++ doesn't have template
'typedef's, but there is a well-known idiom that comes pretty close

template<typename T> struct rSharedPointer {
typedef boost::shared_ptr<T> type;
};

However, in this case you'll have to declare your 'rSharedPointer's as
follows

rSharedPointer<int>::type ptr;

This is probably different from what you currently have. If this is
unacceptable for you, you'll probably have to stick with
preprocessor-based solution suggested by Victor.

--
Best regards,
Andrey Tarasevich

Jul 22 '05 #4

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

Similar topics

2
2837
by: FrankS | last post by:
Hi All, I have a problem with an call-template cmd at xslt 1.0: With: pCall = 'ExInput' ------ I try to: <xsl:call-template name="{$pCall}"> <xsl:with-param name="pVal" select="$pValue"/>...
5
1838
by: William Payne | last post by:
Hello, consider the following two classes (parent and child): #ifndef SINGLETON_HPP #define SINGLETON_HPP #include <cstddef> /* NULL */ template <typename T> class Singleton {
4
1421
by: HG | last post by:
Hi gurus Sorry the rather long post... I am facing a real world problem here, and I dunno how to approach it. Don't even know if this is the right group...but since my app is ASP.NET I tried...
18
2429
by: skishorev | last post by:
Hi, Here I am taking two functions. void f(int,int) and another one is float f(int,int). Is it possible to overload with return values. Thx, kishore
2
1441
by: esuvs81 | last post by:
Hi guys, is it possible to use partial specialization on individual member functions of a class (rather than partially specializing the whole class)? I have the following code: #include...
7
9430
by: quarup | last post by:
I want to specialize a template function that lives inside a class, but am getting a compile error in VS.net 2003. Here's my code: template <class T> class A { public: template <class U> void...
5
1780
by: patrin | last post by:
Hi All, given the source document: <?xml version="1.0" encoding="UTF-8"?> <root> <child> <test id="1" name="first child"/> </child> <child>
4
1488
by: Lord0 | last post by:
Hi there, Is the following possible with XSLT? Given the following example XML docs: <!-- doc 1--> <user> <username>myUsername</username> <password></password> <phone>12345</phone>
6
2879
by: year1943 | last post by:
For template <typename Tclass My ; I can define partial spec-ns somewhat like template <typename Tclass My<T*; or template <typename Tclass My<Another<T ; And full spec-n, say template <class...
6
1350
by: Peng Yu | last post by:
Hi, I want B has all the constructors that A has. Obviously, the code below would not work. I could define a corresponding B's constructor for each A's constructor. But if A has many...
0
7123
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...
0
7326
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,...
0
7383
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...
1
7046
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...
0
7498
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...
0
5627
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,...
0
4707
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...
0
3194
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...
0
1557
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 ...

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.