| | |
How to use typedef for the template structure? What its syntax?
![]() |
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..
C++ Syntax (Toggle Plain Text)
#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
C++ Syntax (Toggle Plain Text)
typedef box square;
But i didn't workout... Please help me..
Last edited by Rhohitman; Oct 10th, 2008 at 2:34 am. Reason: mistakely pressed tab and enter.. as it was summited without completion
•
•
Join Date: Jun 2007
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.
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...
C++ Syntax (Toggle Plain Text)
typedef box<int> MyFavouriteBoxType; ... MyFavouriteBoxType b1;
•
•
Join Date: Jun 2008
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 11:23 am.
•
•
•
•
What's a problem?
Look at STL headers on you C++ installation. There are lots of (useful) typedefs in STL templates...C++ Syntax (Toggle Plain Text)
typedef box<int> MyFavouriteBoxType; ... MyFavouriteBoxType b1;
Last edited by Rhohitman; Oct 10th, 2008 at 12:59 pm.
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;

Can you kindly explain it..
Last edited by Rhohitman; Oct 10th, 2008 at 1: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
C++ 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...
C++ 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
| Thread Tools | Search this Thread |
api array based binary bitmap business c++ c/c++ char class classes code coding commentinghelp compile console conversion count decide delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez graph guess gui homeworkhelp homeworkhelper iamthwee ifpug ifstream incrementoperators infinite input int integer java lib linkedlist linker loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem proficiency program programming project python random read recursion reference rpg string strings temperature template templates test text text-file tree url variable vector video win32 windows winsock word wordfrequency wxwidgets






