template problem: using a reference to object as a non-type argument

S

shortymike007

#include <iostream>

template <int dv[3]>
class A {};

template <A &a>
class B {};

extern int vec[3] = {1,0,0};
extern A< vec > *a;

void main()
{
B<a> b;
}



I'm getting some errors about specialization that I don't understand. Any help in the right direction would be appreciated. Thanks
 
I

Ian Collins

#include <iostream>

template <int dv[3]>
class A {};

template <A &a>

A is a class template, are you trying to declare a template template?
class B {};

extern int vec[3] = {1,0,0};
extern A< vec > *a;

void main()

The return type of main in int.
{
B<a> b;

The compiler won't have a clue by the point (because of previous errors)....
 
S

shortymike007

#include <iostream>
template <int dv[3]>
class A {};

template <A &a>



A is a class template, are you trying to declare a template template?


class B {};
extern int vec[3] = {1,0,0};
extern A< vec > *a;

void main()



The return type of main in int.





The compiler won't have a clue by the point (because of previous errors)....

I'm not trying to declare a template template. I would like to use A as a nontype argument for template B.
 
V

Victor Bazarov

#include <iostream>

template <int dv[3]>
class A {};

template <A &a>

A is a class template, are you trying to declare a template template?
class B {};

extern int vec[3] = {1,0,0};
extern A< vec > *a;
void main()

The return type of main in int.
{
B<a> b;

'a' is a pointer and the template argument of 'B' is a reference. You
probably should think of dereferencing 'a' here, like

B said:
I'm not trying to declare a template template. I would like to use A as a nontype argument for template B.

What's the type of the non-type argument? 'A' is not a type. You need
to supply the template argument for 'A' to instantiate it to make it a
type, which then you can use to declare the non-type argument.

Something like

template <A<vec> &a> class B {};

Perhaps you could be a bit more specific about your goal here. What is
it you're trying to accomplish?

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,818
Latest member
Brigette36

Latest Threads

Top