delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/01/27/03:00:20

From: Robert White <HumansRemoveThis_rwhite AT pobox DOT com>
Newsgroups: comp.lang.c++,comp.os.msdos.djgpp,rec.games.programmer
Subject: Re: Template Class as Object Function Parameter
Date: Tue, 27 Jan 1998 02:47:01 -0500
Organization: Bell Atlantic Internet Solutions
Lines: 50
Message-ID: <34CD90F4.9736DD18@pobox.com>
References: <34C8192D DOT 6DE290C4 AT nwrain DOT com>
NNTP-Posting-Host: client-151-200-122-209.bellatlantic.net
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

The following is an primary example of an unanswerable question.

You need to tell us what errors you are getting and sow us the code that is
*calling* the template.  The errors you are getting are almost certianly an
invocation time issue and not an definition time issue.  The tiny (deleted
for brevity) code fragment you provided in your original article is
syntatically correct so the problem is doubtless elsewhere.

Neil & Joey Obremski wrote:

> And in one function I wish to have a
> parameter that is of this class and the SAME type as the current class
> object.  So I naturally thought that 'Array<dt> *src' would work, but i
> get errors.

BTW:

template <class T>
class Array    {
...
    typedef    Array<T>    MyType;  // Handy type renaming to reduce
confusion
    int                               copy(MyType &, long); //Almost always
copy "references"
...
};

template<class T>
int    Array<T>::copy(MyType & Oroginal, long StartPos)    {
}

And furthermore:

You "probably" would be better off writing this as a copy constructor and
then an assignment operator then "adding in" the Start Position to the two
afore mentioned functions.  I note this because your choice of return type
(taken from original post) indicates that you are not so much "making a new
copy of" the supplied input, as much as you are "replacing the contents of
the current array with a copy of" the supplied input.  The "starting at a
spesific offset" is far less significant a factor than the "replace".

LASTLY:

Do be sure to check to be sure that (&Original != this) before you start to
monkey around because if (&Original == this) then you have a "trim" not an
copy to do...

Rob.
Remove Anti-Spam from my return address to reply via email.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019