template subclass needs to be public? 
Author Message
 template subclass needs to be public?

in VC++ 7.0 the following code does not compile, unless you remove the
comment in 4th line.
moreover, the error message looks quite strange:

d:\star\test\t03\t03.cpp(18) : error C2247: 'raise_to_pow<T>::pow<n>::apply'
not accessible because 'raise_to_pow<T>' uses 'private' to inherit from
'raise_to_pow<T>::pow<n>'

[I know the code itself seems useless, but it's just to hear if it's a known
bug or not]

template <class T>
class raise_to_pow
{

// public:
    template <int n>
    class pow
    {
        public:
        static T apply(T x)
        {
            return x * pow<n-1>::apply(x) ;
        }
    };

    template <>
    class pow<0>
    {
        public:
        static T apply(T x)
        {
        return 1;
        }
    };

public:

static T compute(T x)
{
return pow< sizeof(T) >::apply(x);

Quote:
}
};

int main()
{
double x = 3.14;
double y = raise_to_pow<double>::compute(x);        // y = pow(3.14 ,8),
since sizeof(double) is 8
return 0;

Quote:
}

--
 The set of solutions is never empty
 Two solutions together form a new problem
-- Mycroft Holmes


Sun, 27 Feb 2005 16:41:02 GMT  
 template subclass needs to be public?

Quote:
> in VC++ 7.0 the following code does not compile, unless you remove the
> comment in 4th line.
> moreover, the error message looks quite strange:

Known bug.

-cd



Sun, 27 Feb 2005 21:30:50 GMT  
 template subclass needs to be public?

Quote:

> in VC++ 7.0 the following code does not compile, unless you remove the
> comment in 4th line.
> moreover, the error message looks quite strange:

> d:\star\test\t03\t03.cpp(18) : error C2247: 'raise_to_pow<T>::pow<n>::apply'
> not accessible because 'raise_to_pow<T>' uses 'private' to inherit from
> 'raise_to_pow<T>::pow<n>'

> [I know the code itself seems useless, but it's just to hear if it's a known
> bug or not]

You should post something like this to
microsoft.public.dotnet.languages.vc


Sun, 27 Feb 2005 21:47:14 GMT  
 template subclass needs to be public?

Quote:
> Known bug.

known by who? ;)

--
{
    bool set<solution>::is_empty() { return false; }
    problem& operator+ ( solution&, solution& ) { return *new problem(); }

Quote:
} /* Mycroft Holmes */



Sun, 27 Feb 2005 23:13:39 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. template subclass needs to be public? (repost)

2. Subclasses or custom control in CDialogBar or other template

3. CDialog, subclass or not to subclass?

4. Some help needed to subclass Sliders

5. Public or non-Public Constructor

6. public NNTP server for microsoft.public.vc.database ?

7. microsoft.public.vc.mfc, microsoft.public.vc.ide_general

8. new public void draw() versus public void override draw()

9. Needed: a public domain regular expression interpreter

10. Need Comm library or routines...public domain

11. I need a public domain codeline managing program for dos

12. public domain C code for tftp daemon needed

 

 
Powered by phpBB® Forum Software