home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / cplus / 12742 < prev    next >
Encoding:
Internet Message Format  |  1992-08-21  |  1.3 KB

  1. Path: sparky!uunet!haven.umd.edu!darwin.sura.net!mips!sdd.hp.com!uakari.primate.wisc.edu!ames!pacbell.com!UB.com!igor!dirac!rmartin
  2. From: rmartin@dirac.Rational.COM (Bob Martin)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Constructor arguments for template classes
  5. Message-ID: <rmartin.714435608@dirac>
  6. Date: 21 Aug 92 22:20:08 GMT
  7. References: <1992Aug20.224111.2017@lgc.com>
  8. Sender: news@Rational.COM
  9. Lines: 43
  10.  
  11. srinivas@lgc.com (Manapragada Srinivas) writes:
  12.  
  13.  
  14. |Hi,
  15.  
  16. |    I  have a question about templates -
  17.  
  18. |    Suppose I design a Vector template class as follows
  19.  
  20. |    template <class T>
  21. |    class Vector
  22. |    {
  23. |    public:
  24. |        Vector( int size );
  25. |        // ... destructors, private members etc.
  26.  
  27. |    }
  28.  
  29. |    a. Does Vector< Vector<int> > make sense?
  30.  
  31. |    b. If so how do I initialize it?
  32.  
  33. |        g++ is not happy about
  34. |            Vector< Vector<int> > vec(10);
  35.  
  36. |        nor does it accept
  37. |            Vector< Vector<int> > vec(10, 10);
  38.  
  39. I think you need to supply a specific constructor for this class.  You
  40. can do this by overiding the one produced by the template
  41.  
  42. Vector< Vector < int > > :: Vector< Vector < int > >
  43. : /* now initialize your inner vector... */
  44. {
  45.    ...
  46. }
  47.  
  48.  
  49. --
  50. Robert Martin                        Training courses offered in:
  51. R. C. M. Consulting                       Object Oriented Analysis
  52. 2080 Cranbrook Rd.                        Object Oriented Design
  53. Green Oaks, Il 60048 (708) 918-1004       C++
  54.