Topic: Template problem


Author: je@bton.ac.uk (John English)
Date: 1995/06/15
Raw View
Maciej Pilichowski (macias@class1) wrote:
: : template <class T>
: : class What
: : {
: :     public:
: :     typedef int MyNumber;

: :     static MyNumber aNumber;
: : };

: : template <class T>
: :     What<T>::MyNumber What<T>::aNumber = 0;

: : Error:  What<T>::MyNumber is not accessible

Oh dear.  Another buggy compiler.  Which one?

: Certainly "MyNumber" is not accessible because it is not a field - just a
: type.

So what?  It's an identifier in the public section, so it should be publicly
visible, no?  What difference does it make whether it's a type name or not?

: Besides you didn't write any method so why you try to do something
: outside this class?

He's trying to supply a definition (required) for a static member!  This
*must* be allowed...

: template <class T>
: void What<T>::your_method()
: {
:   aNumber=0;
: };

: will be enough.

...*won't* be enough.  No storage has been reserved for aNumber.  You've
missed the point.

--
----------------------------------------------------------------------------
John English <je@brighton.ac.uk>, Dept. of Computing, University of Brighton
  "The Tory party is the cream of society: rich, thick, and full of clots"
----------------------------------------------------------------------------





Author: arnoud@ijssel.xs4all.nl (Arnoud Martens)
Date: 1995/06/03
Raw View
In article <Pine.OSF.3.91.950531132615.20591A-100000@hubble.sheridanc.on.ca>,
savio desouza  <desouza@hubble.sheridanc.on.ca> wrote:
> I was wondering if anyone could help me out on this problem that
>I am having with Borland C++ 4.02.  Here is the code:
>
>template <class T>
>class What
>{
>    public:
>    typedef int MyNumber;
>
>    static MyNumber aNumber;
>};
>
>template <class T>
>    What<T>::MyNumber What<T>::aNumber = 0;

There is no actual class what<T> only instantiations of it like
what<int> exist. So:

what<int>::MyNumber what<int>MyNumber = 0;

should work. Note that all instances of what<int> share this same
variable just like all what<float> instances have their own
instances. There are not that many compilers that allow you to do this
though., although it is valid C++. Don't know if Borland C++ is one of
them.

--
Arnoud Martens             | arnoudm@ijssel.xs4all.nl
Utrecht, the Netherlands   | http://www.xs4all.nl/~arnoudm





Author: macias@class1 (Maciej Pilichowski)
Date: 1995/06/04
Raw View
Hi there,

: template <class T>
: class What
: {
:     public:
:     typedef int MyNumber;

:     static MyNumber aNumber;
: };

: template <class T>
:     What<T>::MyNumber What<T>::aNumber = 0;

: Error:  What<T>::MyNumber is not accessible

Certainly "MyNumber" is not accessible because it is not a field - just a
type. Besides you didn't write any method so why you try to do something
outside this class?

template <class T>
void What<T>::your_method()
{
  aNumber=0;
};

will be enough.

hope it helps
have a nice day
bye
--
Maciej "MACiAS" Pilichowski
ul. Chodkiewicza 12b/5
87-100 Torun, Poland
tel. (+48) (0-56) 334-34
e-mail: macias@vm.cc.uni.torun.pl
        macias@class1.phys.uni.torun.pl





Author: savio desouza <desouza@hubble.sheridanc.on.ca>
Date: 1995/05/31
Raw View
Hi
 I was wondering if anyone could help me out on this problem that
I am having with Borland C++ 4.02.  Here is the code:

template <class T>
class What
{
    public:
    typedef int MyNumber;

    static MyNumber aNumber;
};

template <class T>
    What<T>::MyNumber What<T>::aNumber = 0;

void main()
{
}


Error:  What<T>::MyNumber is not accessible

Why am I getting this error?  Any help would be appreciated. Thanks