🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: de.comp.lang.c++
1 messages
1 total messages Started by Achim Dreyer Thu, 07 Dec 1995 15:34
Template problem with SPARCompiler C++
#973
Author: 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
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