#include <stdio.h>
#include <iostream>
using namespace std;
template <typename T> class counted_ptr;
template <typename T>
void test1(const counted_ptr<T>& l);
template <typename T, typename U>
void test2(const counted_ptr<T>& l, const counted_ptr<U>& r);
template <typename T>
class counted_ptr
{
friend void test1<T>(const counted_ptr<T>& l);
template <typename U>
friend void test2<T>(const counted_ptr<T>& l, const counted_ptr<U>& r);
public:
counted_ptr() {};
~counted_ptr() {};
};
template <typename T>
void test1(const counted_ptr<T>& l)
{
cout << "test1!" << endl;
}
template <typename T, typename U>
void test2(const counted_ptr<T>& l, const counted_ptr<U>& r)
{
cout << "test2!" << endl;
}
編譯報錯:
template <typename U>
friend void test2<T>(const counted_ptr<T>& l, const counted_ptr<U>& r);
[BCC32 Error] File2.cpp(26): E2401 Invalid template argument list
Full parser context
File2.cpp(22): class counted_ptr<T>
uj5u.com熱心網友回復:
template <typename T, typename U>void test2(const counted_ptr<T>& l, const counted_ptr<U>& r)
{
cout << "test2!" << endl;
}
你的這個陳述句中的第二個引數 const counted_ptr<U>& r 不是很理解如果你是兩種型別,那么不是應該在類定義之前寫
template<typename T,typename U>的嗎? 或者你就改成const counted_ptr<T>& r
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/90189.html
標籤:基礎類
上一篇:想請問一下3層if嵌套的等價形式
