🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.g++.bug
Article #1248

Template bug...

#1248
From: Jeff Gehlhaar
Date: Fri, 11 Dec 1992 09:25
88 lines
3319 bytes
The following code illustrates another template bug. 

It appears that the following:
          vector< vector<int> > u = vector< vector<int> >(vector<int>(1));

Does not create an instantiation of vector<int>. Thus causing the problem later.

::::::::::::::
does not compile (would compile if x[i] were explicitly cast to type T in
the operator << routine)
::::::::::::::
::::::::::::::
test.c
::::::::::::::
#include <stream.h>

/***************************************************************************
***
 * vector template definition
 ***************************************************************************
***/
template<class T> class vector {
private:
  T v[2];
public:
     vector(void)              {}
     vector(const T& y);

  T& operator [] (int i) const { return v[i]; }
};
template<class T> ostream& operator << (ostream& s, const vector<T>& x);


/***************************************************************************
***
 * vector template routines
 ***************************************************************************
***/
template <class T> vector<T>::vector(const T& y)
{
  for (int i = 0; i < 2; i++) v[i] = y;
}
template <class T> ostream& operator << (ostream& s, const vector<T>& x)
{
  for (int i = 0; i < 2; i++) s << x[i] << " ";
  return s;
}


/***************************************************************************
***
 * main routine
 ***************************************************************************
***/
int main(void)
{
//  vector<int>           x = vector<int>(1);
  vector< vector<int> > u = vector< vector<int> >(vector<int>(1));

//  cout << "x:    " << x    << "\n";
  cout << "u:    " << u    << "\n";
}
::::::::::::::
compilation output (g++ -v test.c -o test)
::::::::::::::
Reading specs from /usr/local/lib/gcc-lib/sparc-sun-sunos4.1/2.3.2/specs
gcc version 2.3.2
 /usr/local/lib/gcc-lib/sparc-sun-sunos4.1/2.3.2/cpp -lang-c++ -v -undef
-D__GNUC__=2 -D__GNUG__=2 -D__cplusplus -Dsparc -Dsun -Dunix -D__sparc__
-D__sun__ -D__unix__ -D__sparc -D__sun -D__unix test.c /usr/tmp/cca10091.i
GNU CPP version 2.3.2 (sparc)
 /usr/local/lib/gcc-lib/sparc-sun-sunos4.1/2.3.2/cc1plus
/usr/tmp/cca10091.i -quiet -dumpbase test.cc -version -o
/usr/tmp/cca10091.s
GNU C++ version 2.3.2 (sparc) compiled by CC.
test.c: In function `class ostream& operator << (class ostream&, const
class vector<vector<int>>&)':
test.c:27: no constructor named `vector' in visible scope
test.c:27: no constructor named `vector' in visible scope
test.c:27: no constructor named `vector' in visible scope
test.c:27: no constructor named `vector' in visible scope


======================================================
Jeff Gehlhaar           Qualcomm Inc,  
jbg@qualcomm.com        San Diego, CA, USA
(619) 597-5241          "The Elegant Solution...."
======================================================
Technical Details
Message-ID: <9212120025.AA14127@harvey>
Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!qualcomm.com!jbg

Show Full Headers
Complete Article Headers
Newsgroups: gnu.g++.bug
Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!qualcomm.com!jbg
From: jbg@qualcomm.com (Jeff Gehlhaar)
Subject: Template bug...
Message-ID: <9212120025.AA14127@harvey>
Sender: gnulists@ai.mit.edu
Organization: GNUs Not Usenet
Distribution: gnu
Date: Fri, 11 Dec 1992 09:25:52 GMT
Approved: bug-g++@prep.ai.mit.edu
Lines: 90