🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: de.comp.lang.c++
Article #973

Template problem with SPARCompiler C++

#973
From: Achim Dreyer
Date: Thu, 07 Dec 1995 15:34
141 lines
3763 bytes
Hallo,


Ich hatte den folgenden Artikel schon mal in comp.lang.c++ gepostet aber keine Antwort
bekommen. Vielleicht kann mir hier jemand weiter helfen ..


Kann mir jemand sagen was bei dem folgenden Code-Segment der Fehler ist ??

---- snip ----
::::::::::::::
3_a.h
::::::::::::::
//   header file for template a

#ifndef _a_
#define _a_

#include <iostream.h>

#ifndef NULL
#define NULL 0
#endif

template<class T, int n>
class  a {

private:
        T*      d;

public:
        a(void);
        a(const a<T,n>& c);
        ~a(void);
        friend ostream& operator<< (ostream& o, const a<T,n>& c);
        friend istream& operator>> (istream& i, a<T,n>& c);

};

#endif
::::::::::::::
3_a.cc
::::::::::::::
//

#include "3_a.h"
#include <iostream.h>

template<class T, int n>
a<T,n>::a(void)
{       d = ( (T*) NULL );      }

template<class T, int n>
a<T,n>::a(const a<T,n>& c)
{       d = new T[n];           }

template<class T, int n>
a<T,n>::~a(void)
{       delete [] d;            }

template<class T,int n>
ostream& operator<< (ostream& o, const a<T,n>& c)
{
        if ( c.d )
                return o << c.d[0];
        else
                return o;
}

template<class T, int n>
istream& operator>> (istream& i, a<T,n>& c)
{
        c.d = new T[n];
        for (int j=0; j<n; j++)
                i >> c.d[j];
        return i;
}

// dummies

static void a_dummy()
{
        a<int,4> xx;
        a<int,4>* yy,zz;
        yy =  new a<int,4>;
        delete yy;
        cout << xx;
        cin >> xx;
}
::::::::::::::
3_c.cc
::::::::::::::
//

#include "3_a.h"
#include <iostream.h>
#include <iomanip.h>

int main( int, char** )
{

        a<int,4>        afield;
        
        cout << "Hallo" <<endl;
        
};
---- snip -----

with g++ (V. 2.7.2) for solaris everything gets compiled without any
warnings (except about the iostrem-lib. and then dummy function) when
using  "g++ -g -Wall -Wshadow -Wtemplate-debugging -Wconversion".

When using CC (SPARCompiler C++ Version 3.01) for Solaris I get :



adreyer@wiwianka [tmp] > CC -o 3_c 3_a.cc 3_c.cc
3_a.cc:
"3_a.cc", line 20: Error: The template argument n is not a type.
"3_a.cc", line 29: Error: The template argument n is not a type.
"3_a.cc", line 44: Error: Formal argument c of type const a<int, n>& in call to operator<<(ostream&, const a<int, n>&) is being passed a<int, 4>.
"3_a.cc", line 45: Error: Formal argument c of type a<int, n>& in call to operator>>(istream&, a<int, n>&) is being passed a<int, 4>.
4 Error(s) detected.
3_c.cc:
template manager : Warning: No valid template database available.  Creating default repository "Templates.DB".
"3_a.cc", line 20: Error: The template argument n is not a type.
"3_a.cc", line 29: Error: The template argument n is not a type.
"3_a.cc", line 44: Error: Formal argument c of type const a<int, n>& in call to operator<<(ostream&, const a<int, n>&) is being passed a<int, 4>.
"3_a.cc", line 45: Error: Formal argument c of type a<int, n>& in call to operator>>(istream&, a<int, n>&) is being passed a<int, 4>.
4 Error(s) detected.



As far as I can see from the Answerbook (C++ 4.0 User's Guide)
this is legal syntax  ?!?

Have done it wrong or this there anywhere a feature/bug that I'm
missing ??

Thanx in advance,
	Achim
Technical Details
Message-ID: <4a71i7$jbo@news.uni-paderborn.de>
Path: arc1-ca.pugleaf.net!uni-paderborn.de!adreyer

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!uni-paderborn.de!adreyer
From: adreyer@uni-paderborn.de (Achim Dreyer)
Newsgroups: de.comp.lang.c++
Subject: Template problem with SPARCompiler C++
Date: 7 Dec 1995 15:34:31 GMT
Organization: Universitaet Paderborn, Germany
Message-ID: <4a71i7$jbo@news.uni-paderborn.de>
NNTP-Posting-Host: vieta.uni-paderborn.de
X-Newsreader: TIN [version 1.2 PL2]