home *** CD-ROM | disk | FTP | other *** search
- Path: nntp-trd.UNINETT.no!usenet
- From: Paul Kenneth Egell-johnsen <paulken4@afrodite.kih.no>
- Newsgroups: comp.lang.c++
- Subject: templates, arguments and pointers
- Date: Thu, 18 Apr 1996 15:08:30 +0200
- Organization: UNINETT news service
- Message-ID: <31763ECE.352C@afrodite.kih.no>
- NNTP-Posting-Host: afrodite.kih.no
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.01 (X11; I; HP-UX A.09.05 9000/720)
-
- Here is a problem we have:
-
- template <class D>
- class Matrix : public Grid<D>
- {
- public:
- Matrix();
- Matrix(size_t rows, size_t cols);
- etc.
- }
-
- class tobject
- {
- public:
- tobject();
- ~tobject();
- private:
- Matrix<int> *pointer;
- }
-
- tobject::tobject()
- {
- int i;
- pointer = new Matrix<int>(23,23); // is this construct valid?
- }
-
- My problem is in the constructor of tobject. The Matrix class
- (are from a book, and all examples pertaining to it, just
- instantiates the objects with those two arguments always, never
- dealing with pointers to the Matrix class) demands (as it is
- now) the two arguments, saying how wide and how high it should
- be.
-
- The standard way to fill in a Matrix object is this:
-
- Matrix<int> A(2,2);
-
- A(0,0) = 1;
- A(0,1) = 2;
-
- How would this work with pointers:
-
- *this->pointer(0,0) = 1;
- *this->pointer(0,1) = 2;
-
- For those of you who would know whihc book we used, it is:
-
- C++ Templates and Tools,
- Scott Robert Ladd,
- M&T Books
-
- Infact we just dropped the Matrix class in our implementation,
- but we think that the problem is an interesting one.
-
- Of course we could put in a set function...but now that we have
- this problem, lets see how it's solved.
-
- Any help would be very appriciated.
-
- Paul K Egell-Johnsen,
-
- mailto:paulken4@afrodite.kih.no
- http://afrodite.kih.no:8001/studenter/paulken4/frames/
-