How to use typedef for the template structure? What its syntax?
Please support our C++ advertiser: Programming Forums
![]() |
I create the simple template structure like this
Now i want to use the typedef for this template structure.
I could not figure out the syntax...
as i tried
But i didn't workout... Please help me..
#include <iostream>
template <class info>
struct box
{
info data;
};
int main()
{
box<int> b1;
b1.data = 1;
std::cout<<b1.data;
return 0;typedef box square;
}Now i want to use the typedef for this template structure.
I could not figure out the syntax...
as i tried
typedef box square;
But i didn't workout... Please help me..
Last edited by Rhohitman : Oct 10th, 2008 at 1:34 am. Reason: mistakely pressed tab and enter.. as it was summited without completion
•
•
Posts: 275
Reputation:
Solved Threads: 45
I don't think it's in the language.
You could use #define square box.
You may want to google template typedefs, or check out http://www.gotw.ca/gotw/079.htm for some solutions.
You could use #define square box.
You may want to google template typedefs, or check out http://www.gotw.ca/gotw/079.htm for some solutions.
•
•
•
•
I don't think it's in the language.
You could use #define square box.
You may want to google template typedefs, or check out http://www.gotw.ca/gotw/079.htm for some solutions.
Couldn't understand your like... but might come handy later... thanx
Chazing Dreams ;'P
Shhhh.......ZZzzzzzzzzzzzzzzzzzzzz.....
Shhhh.......ZZzzzzzzzzzzzzzzzzzzzz.....
What's a problem?
Look at STL headers on you C++ installation. There are lots of (useful) typedefs in STL templates...
cplusplus Syntax (Toggle Plain Text)
typedef box<int> MyFavouriteBoxType; ... MyFavouriteBoxType b1;
•
•
Posts: 86
Reputation:
Solved Threads: 5
yea, you gotta either macro it or typedef with specifying the actual template type
sucks in a way... but hey, what's the deal with the box thing, it's pretty small and easy to write...
i use typedef for long, looooong names, like:
and then i just sit... all the way... rocks
sucks in a way... but hey, what's the deal with the box thing, it's pretty small and easy to write...i use typedef for long, looooong names, like:
c++ Syntax (Toggle Plain Text)
typedef my_monumental_structure<another_huge_type>::iterator sit;
Last edited by gregorynoob : Oct 10th, 2008 at 10:23 am.
•
•
•
•
What's a problem?
Look at STL headers on you C++ installation. There are lots of (useful) typedefs in STL templates...cplusplus Syntax (Toggle Plain Text)
typedef box<int> MyFavouriteBoxType; ... MyFavouriteBoxType b1;
Is there any possibilities to have generic type typedef. As normally typedef copies complete characteristics of it host.
Last edited by Rhohitman : Oct 10th, 2008 at 11:59 am.
Chazing Dreams ;'P
Shhhh.......ZZzzzzzzzzzzzzzzzzzzzz.....
Shhhh.......ZZzzzzzzzzzzzzzzzzzzzz.....
•
•
•
•
yea, you gotta either macro it or typedef with specifying the actual template typesucks in a way... but hey, what's the deal with the box thing, it's pretty small and easy to write...
i use typedef for long, looooong names, like:and then i just sit... all the way... rocksc++ Syntax (Toggle Plain Text)
typedef my_monumental_structure<another_huge_type>::iterator sit;
I didn't get what your syntax says.

Can you kindly explain it..
Last edited by Rhohitman : Oct 10th, 2008 at 12:51 pm.
Chazing Dreams ;'P
Shhhh.......ZZzzzzzzzzzzzzzzzzzzzz.....
Shhhh.......ZZzzzzzzzzzzzzzzzzzzzz.....
I believe he's trying to do something like:
I don't think it can be done
cplusplus Syntax (Toggle Plain Text)
typedef box MyGreatBeautifulBox; //and use it as: MyGreatBeutifulBox<int> a; MyGreatBeutifulBox<char>b;
I don't think it can be done
Hehe...
cplusplus Syntax (Toggle Plain Text)
template<typename T> struct MyGreatBeautifulBox:box<T>{}; int main() { MyGreatBeautifulBox<int> ibox; MyGreatBeautifulBox<char> cbox;
![]() |
Other Threads in the C++ Forum
- Previous Thread: number of ways to..ehh, i hate counting ways
- Next Thread: Using c++ to send email with smtp
•
•
•
•
Views: 1553 | Replies: 12 | Currently Viewing: 1 (0 members and 1 guests)






Linear Mode