🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by Tracey Beauchat Wed, 28 Oct 1992 08:15
BUG?
#9
Author: Tracey Beauchat
Date: Wed, 28 Oct 1992 08:15
76 lines
2323 bytes
It appears that templates are implemented in the latest g++, right?  Well
when I try to compile the following simple test program I get the following
compiler errors:

tracey@md> g++ -c temp.c 
temp.c:16: parse error before `>'
temp.c:35: warning: return type for `main' changed to integer type
temp.c:10: parse error before `>'
temp.c: In function `int  main (...)':
temp.c:13: template for method `junk' doesn't match any in class `junk<junk2>'

It appears that g++ can't handle passing template classes into methods.
Is this true?

-Tracey

------------ THE PROGRAM --------------

#include <iostream.h>

template <class T>
class junk {
  T *data;
  int size;

public:
  junk(int n) { data = new T[n]; size = n; }
  junk(junk<T> &);
  void Put(int i, T d) { data[i] = d; }
  T& Get(int i);
};

template <class T>
junk<T>::junk(junk<T> &j)
{
   data = new T[j.size];
   size = j.size;
}

template <class T> 
T& junk<T>::Get(int i)
{
  return(data[i]);
}

struct junk2 {
  int d;
};


void
main(void)
{
   junk <junk2> test(2);
   junk2 a;

   a.d = 2;

   test.Put(0, a);
   a = test.Get(0);
}

-------------- END --------------

-------------------------------------------------------------------
                        Tracey A. Beauchat
-------------------------------------------------------------------
*********   *********   ********
*********   ***   ***   ***   ***    The College of William & Mary
   ***      *********   ********     Department of Computer Science
   ***      ***   ***   ***   ***    Williamsburg, VA  23185
   ***      ***   ***   ********
-------------------------------------------------------------------
       EMAIL: tracey@cs.wm.edu         PHONE: (804)221-3468
-------------------------------------------------------------------
         <-[ " The truth is a virus! " - Harry Hardon ]->
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads