Invalid friend declarations in template

Hi,

I have the following code which does not want to compile:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
template<typename RatioSequence, size_t N>
struct ratio_sequence_multiply
{
	template<typename RatioSequence>
	friend struct ratio_sequence_multiply<RatioSequence, 0>;

	template<typename RatioSequence, size_t N>
	friend struct ratio_sequence_multiply<RatioSequence, N - 1>;

	private:
	typedef typename mpl::at_c<RatioSequence, N>::type this_ratio;
	typedef typename ratio_sequence_multiply<RatioSequence, N - 1>::this_ratio	prev_ratio;

	public:
	typedef std::ratio_multiply<prev_ratio, this_ratio> accumulative_ratio;
};

template<typename RatioSequence>
struct ratio_sequence_multiply<RatioSequence, 0>
{
	private:
	typedef typename mpl::at_c<RatioSequence, 0>::type this_ratio;
	public:
	typedef this_ratio accumulative_ratio;
};


I get:


ratio_sequence_multiply<RatioSequence,N->': invalid friend template declaration
ratio_sequence_multiply<RatioSequence,0>': invalid friend template declaration


Thanks!

Juan Dent
remove lines 5 and 7
In
1
2
3
4
5
	template<typename RatioSequence>
	friend struct ratio_sequence_multiply<RatioSequence, 0>;

	template<typename RatioSequence, size_t N>
	friend struct ratio_sequence_multiply<RatioSequence, N - 1>;

the template parameters of the outer template are shadowed; this is not allowed.

This won't shadow the template parameters,
template < typename RS > friend struct ratio_sequence_multiply<RS,0>;
But then, the template declaration would be treated as a specialisation; and specilisations must be placed at namespace scope.

This is probably what you intended:
1
2
3
4
5
6
7
8
9
template< typename RatioSequence, std::size_t N >
struct ratio_sequence_multiply
{
	friend ratio_sequence_multiply< RatioSequence, 0 >;

	friend ratio_sequence_multiply< RatioSequence, N-1 >;

    // ...
};
I tried with your suggestion:

1
2
3
4
5
6
7
8
9
template< typename RatioSequence, std::size_t N >
struct ratio_sequence_multiply
{
	friend ratio_sequence_multiply< RatioSequence, 0 >;

	friend ratio_sequence_multiply< RatioSequence, N-1 >;

    // ...
};


but it does not work either

regards,
Juan
> but it does not work either

File a bug report (along with the code snippet that does not work).

I'm unable to reproduce this bug with any of the compilers; when I try it, it works as expected.
http://coliru.stacked-crooked.com/a/2dbe8c42f72139ef
http://rextester.com/VQE50640
Thanks ... I have reported the bug to microsoft connect!

Will keep this thread open until they have an answer.

Regards,
Juan
Last edited on
Topic archived. No new replies allowed.