home *** CD-ROM | disk | FTP | other *** search
- 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
- From: rmartin@dirac.Rational.COM (Bob Martin)
- Newsgroups: comp.lang.c++
- Subject: Re: Constructor arguments for template classes
- Message-ID: <rmartin.714435608@dirac>
- Date: 21 Aug 92 22:20:08 GMT
- References: <1992Aug20.224111.2017@lgc.com>
- Sender: news@Rational.COM
- Lines: 43
-
- srinivas@lgc.com (Manapragada Srinivas) writes:
-
-
- |Hi,
-
- | I have a question about templates -
-
- | Suppose I design a Vector template class as follows
-
- | template <class T>
- | class Vector
- | {
- | public:
- | Vector( int size );
- | // ... destructors, private members etc.
-
- | }
-
- | a. Does Vector< Vector<int> > make sense?
-
- | b. If so how do I initialize it?
-
- | g++ is not happy about
- | Vector< Vector<int> > vec(10);
-
- | nor does it accept
- | Vector< Vector<int> > vec(10, 10);
-
- I think you need to supply a specific constructor for this class. You
- can do this by overiding the one produced by the template
-
- Vector< Vector < int > > :: Vector< Vector < int > >
- : /* now initialize your inner vector... */
- {
- ...
- }
-
-
- --
- Robert Martin Training courses offered in:
- R. C. M. Consulting Object Oriented Analysis
- 2080 Cranbrook Rd. Object Oriented Design
- Green Oaks, Il 60048 (708) 918-1004 C++
-