www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/05/24/08:55:31

From: NG Chi Fai <cfng1 AT netvigator DOT com>
Newsgroups: comp.os.msdos.djgpp,comp.lang.c++
Subject: Re: Problems using CYGWIN
Date: Sun, 23 May 1999 17:21:20 -0700
Organization: oronet, Penn Valley, C
Lines: 93
Message-ID: <37489B80.A2A36F88@netvigator.com>
References: <373FBB9C DOT FE26B278 AT netvigator DOT com> <FBvqL7 DOT 6Gr AT research DOT att DOT com> <37422F98 DOT D16AE5AA AT netvigator DOT com> <37484FDF DOT 6F185581 AT enter DOT net>
NNTP-Posting-Host: gv1-246.oro.net
Mime-Version: 1.0
X-Server-Date: 24 May 1999 00:22:02 GMT
X-Mailer: Mozilla 4.51 [en] (Win95; I)
X-Accept-Language: en
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Hello Sean,

Thanks. Sorry for my mistake again, the body of the copy constructor is
defined inside the class definition, I just copied it out to the
message.

Here is a more complete view (I hope). I try to make the copy
constructor a template because in some of my other class I would like to
copy between different instantiation of a template (this piece of code
is for testing only).

template < class T >
class a
{
	public:
		T* t;
		a(void)
		{
			t=new T[256];
		};
		template < class U > a(const a<U> &v)
		{
			t=new T[256];
			*this=v;
		};
		~a(void)
		{
			delete[] t;
		};
		template < class U > a<T> & operator = (const a<U> &v) 
		{
			int i;
			for(i=0;i<256;i++)
			{
				t[i]=T(v.t[i]);
			}
			return *this;
		};
		void fill ( const T & h)
		{
			int i;
			for(i=0;i<256;i++)
			{
				t[i]=h;
			}
		};
		a<T> duplicate(void)
		{
			a<T> temp;
			temp=*this;
			return temp;
		};
		friend ostream & operator << <T> (ostream& out, const a<T>& t);
};

Sean wrote:
> 
> NG Chi Fai wrote:
> >
> > Hello,
> >
> > I've tried to add a copy constructor, but still got the same error:
> >
> > [main] C:\WINDOWS\DESKTOP\A.EXE 1010 (0) handle_exceptions: Exception:
> > STATUS_ACCESS_VIOLATION
> > [main] A 1010 (0) handle_exceptions: Dumping stack trace to A.EXE.core
> >
> > Besides, compiler report as below, but I have no idea what is going on,
> > besides, it seems to warn for the 1st instantiation of a<T>::~a<T> only,
> > it does not warn on a<float>::~a<float>. But when I inverse order of
> > declaration of a<float> and a<int> it warn on a<float>. What is it all
> > about.
> >
> > test.cpp: In instantiation of `a<int>::~a<int>()':
> > test.cpp:65:   instantiated from here
> > test.cpp:65: warning: template `a<int>::~a<int>()' instantiated in file
> > without #pragma interface
> >
> > // copy constructor
> > template < class U > a(const a<U> &v)
> > {
> >         t=new T[256];
> >         int i;
> >         for(i=0;i<256;i++)
> >         {
> >                 t[i]=T(v.t[i]);
> >         }
> > };
> 
> Don't you need the first line of the copy constructor to be
> template<class U> a<U>::a(const a<U> &v)
> ?  I don't really know much about c++, but I know you need something,
> maybe a instead of a<U>, though maybe you just typed it wrong here.

- Raw text -


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