How to use typedef for the template structure? What its syntax?

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Dec 2007
Posts: 68
Reputation: Rhohitman is an unknown quantity at this point 
Solved Threads: 4
Rhohitman's Avatar
Rhohitman Rhohitman is offline Offline
Junior Poster in Training

How to use typedef for the template structure? What its syntax?

 
0
  #1
Oct 10th, 2008
I create the simple template structure like this
  1. #include <iostream>
  2.  
  3. template <class info>
  4. struct box
  5. {
  6. info data;
  7. };
  8.  
  9. int main()
  10. {
  11. box<int> b1;
  12. b1.data = 1;
  13. std::cout<<b1.data;
  14. return 0;typedef box square;
  15. }

Now i want to use the typedef for this template structure.
I could not figure out the syntax...
as i tried
  1. 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
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 275
Reputation: dougy83 is on a distinguished road 
Solved Threads: 45
dougy83 dougy83 is offline Offline
Posting Whiz in Training

Re: How to use typedef for the template structure? What its syntax?

 
0
  #2
Oct 10th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 68
Reputation: Rhohitman is an unknown quantity at this point 
Solved Threads: 4
Rhohitman's Avatar
Rhohitman Rhohitman is offline Offline
Junior Poster in Training

Re: How to use typedef for the template structure? What its syntax?

 
0
  #3
Oct 10th, 2008
Originally Posted by dougy83 View Post
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.....
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 2,001
Reputation: ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of 
Solved Threads: 343
ArkM's Avatar
ArkM ArkM is offline Offline
Postaholic

Re: How to use typedef for the template structure? What its syntax?

 
0
  #4
Oct 10th, 2008
What's a problem?
  1. typedef box<int> MyFavouriteBoxType;
  2. ...
  3. MyFavouriteBoxType b1;
Look at STL headers on you C++ installation. There are lots of (useful) typedefs in STL templates...
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 86
Reputation: gregorynoob is an unknown quantity at this point 
Solved Threads: 5
gregorynoob gregorynoob is offline Offline
Junior Poster in Training

Re: How to use typedef for the template structure? What its syntax?

 
0
  #5
Oct 10th, 2008
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:
  1. typedef my_monumental_structure<another_huge_type>::iterator sit;
and then i just sit... all the way... rocks
Last edited by gregorynoob; Oct 10th, 2008 at 11:23 am.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 68
Reputation: Rhohitman is an unknown quantity at this point 
Solved Threads: 4
Rhohitman's Avatar
Rhohitman Rhohitman is offline Offline
Junior Poster in Training

Re: How to use typedef for the template structure? What its syntax?

 
0
  #6
Oct 10th, 2008
Originally Posted by ArkM View Post
What's a problem?
  1. typedef box<int> MyFavouriteBoxType;
  2. ...
  3. MyFavouriteBoxType b1;
Look at STL headers on you C++ installation. There are lots of (useful) typedefs in STL templates...
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 12:59 pm.
Chazing Dreams ;'P
Shhhh.......ZZzzzzzzzzzzzzzzzzzzzz.....
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 68
Reputation: Rhohitman is an unknown quantity at this point 
Solved Threads: 4
Rhohitman's Avatar
Rhohitman Rhohitman is offline Offline
Junior Poster in Training

Re: How to use typedef for the template structure? What its syntax?

 
0
  #7
Oct 10th, 2008
Originally Posted by gregorynoob View Post
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:
  1. typedef my_monumental_structure<another_huge_type>::iterator sit;
and then i just sit... all the way... rocks
I didn't get what your syntax says.
Can you kindly explain it..
Last edited by Rhohitman; Oct 10th, 2008 at 1:51 pm.
Chazing Dreams ;'P
Shhhh.......ZZzzzzzzzzzzzzzzzzzzzz.....
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 2,001
Reputation: ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of 
Solved Threads: 343
ArkM's Avatar
ArkM ArkM is offline Offline
Postaholic

Re: How to use typedef for the template structure? What its syntax?

 
0
  #8
Oct 10th, 2008
Typedef name is an alias for the type, it's not a new type name.
Can you explain what a problem are you trying to solve with "generic typedef"?
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 273
Reputation: Sci@phy will become famous soon enough Sci@phy will become famous soon enough 
Solved Threads: 42
Sci@phy's Avatar
Sci@phy Sci@phy is offline Offline
Posting Whiz in Training

Re: How to use typedef for the template structure? What its syntax?

 
0
  #9
Oct 10th, 2008
I believe he's trying to do something like:
  1. typedef box MyGreatBeautifulBox;
  2.  
  3. //and use it as:
  4. MyGreatBeutifulBox<int> a;
  5. MyGreatBeutifulBox<char>b;

I don't think it can be done
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 2,001
Reputation: ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of 
Solved Threads: 343
ArkM's Avatar
ArkM ArkM is offline Offline
Postaholic

Re: How to use typedef for the template structure? What its syntax?

 
0
  #10
Oct 10th, 2008
Hehe...
  1. template<typename T>
  2. struct MyGreatBeautifulBox:box<T>{};
  3.  
  4. int main()
  5. {
  6. MyGreatBeautifulBox<int> ibox;
  7. MyGreatBeautifulBox<char> cbox;
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC