Hi all, i have a Vector class (as in mathematical vectors) which is
templatised on two parameters, the length of the vector and it's type
(int,double,etc). I am able to use a typedef like the folowing:
typedef Vector<3,floatVector3DFloat;
Vector3DFloat myVector;
so that users can now use Vector3DFloat as a type in thier code.
However, i would like to just typedef away *one* of the parameters
which i would expect to look something like the following:
typedef Vector<3,TypeVector3D<Type>;
Vector3D<floatmyVector;
The above doesn'tcompile but hopefully illustrates what I am trying to
do. Is there a way to make this work?
Thanks,
David 3 1571 es*****@googlemail.com napsal:
Hi all, i have a Vector class (as in mathematical vectors) which is
templatised on two parameters, the length of the vector and it's type
(int,double,etc). I am able to use a typedef like the folowing:
typedef Vector<3,floatVector3DFloat;
Vector3DFloat myVector;
so that users can now use Vector3DFloat as a type in thier code.
However, i would like to just typedef away *one* of the parameters
which i would expect to look something like the following:
typedef Vector<3,TypeVector3D<Type>;
Vector3D<floatmyVector;
The above doesn'tcompile but hopefully illustrates what I am trying to
do. Is there a way to make this work?
No, there's no elegant solution to this. C++0x will (hopefully) have
"template
typedefs", which is just what you want. If you want further details
including possible workarounds, see http://www.ddj.com/dept/cpp/184403850
Regards
Jiri Palecek es*****@googlemail.com wrote:
Hi all, i have a Vector class (as in mathematical vectors) which is
templatised on two parameters, the length of the vector and it's type
(int,double,etc). I am able to use a typedef like the folowing:
typedef Vector<3,floatVector3DFloat;
Vector3DFloat myVector;
so that users can now use Vector3DFloat as a type in thier code.
However, i would like to just typedef away *one* of the parameters
which i would expect to look something like the following:
typedef Vector<3,TypeVector3D<Type>;
Vector3D<floatmyVector;
The above doesn'tcompile but hopefully illustrates what I am trying to
do. Is there a way to make this work?
Thanks,
David
You cannot typedef templates with the template parameters. However you
can simulate the effect by introducing an intermediate type.
You can refer to Herb Sutter's GOTW here.. http://www.gotw.ca/gotw/079.htm
Ok, thanks to both of you. It looks like i can get around the problem
with Herb Sutters solution until C++0x arrives...
Thanks again,
David This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Roger Leigh |
last post by:
Although I've got over most of my template-related problems, I'm
having trouble when I started to use default template parameters.
For template type T, I've typedef'd this as object_type and then...
|
by: Generic Usenet Account |
last post by:
This is a two-part question.
(1) I have implemented a "Datastructure Registry" template class. I am
getting no compiler warnings with older compilers, but newer compilers
are generating the...
|
by: vvv |
last post by:
Hi All,
Do we have anything in .NET which is equivalent to C++'s Typedef .
Regards,
Vasanth
|
by: jimmy |
last post by:
I am trying to simulate typedef template similar to the suggestion of
Herb Sutter in the following article: http://www.gotw.ca/gotw/079.htm
However when implementing typedef templates according...
|
by: KK |
last post by:
Hello all,
I have several classes binded by one common interface - say 'sum'
interface which calculates the sum of all the class elements of type
'int'.
class Alphabet
{
int _a;
int _b;
int...
|
by: Sacha |
last post by:
I'm aware, that up to date, "typedef templates" are not defined within
the C++ standard. The seemingly common workaround is this:
template <class T> struct MyTypeDef
{
/* ultimately I need...
|
by: Clint Olsen |
last post by:
I was just thinking about the virtues of C vs. C++ wrt. ADT/generic
programming. The biggest complaint about writing container libraries for
ADTs is that void * offers no type safety. Does it...
|
by: Rahul |
last post by:
Hi,
Is there a way to partially specialize only a member function of a
template class (not the whole class).
e.g.
template <typename A, typename B>
class Base
{
public:
|
by: tropos |
last post by:
I'm trying to use the 'typedef templates' idiom, mentioned in
Alexandrescu's work on templates. Here's a Dr Dobbs article from 2002
that says they are a proposed C++ standard:...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
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,...
|
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...
|
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...
| |