Код: Выделить всё
#include
#include
#include
template
class A {
public:
template
friend class A;
template
static A fromOther(A&& other);
private:
int x;
};
template
template
A A::fromOther(A&& other) {
A a;
a.x = other.x;
return a;
}
int main() {
using B = A;
B b = B::fromOther(A());
}
< /code>
MSVC сообщает о нескольких ошибках, начиная с: < /p>
8: error C3855: 'A' template parameter 'U2' is incompatible with the declaration 'T2'
Я также попытался изменить объявление друга, чтобы подружиться с функцией члена: < /p>
template
template
friend A A::fromOther(A&&);
< /code>
Это не создает ошибки в объявлении друга, но переменная частного участника все еще недоступна.
Все варианты, которые я пробовал, работают с GCC, так что мне интересно, является ли это ошибкой в MSVC и как я могу обойти его. < /P.>
Подробнее здесь: https://stackoverflow.com/questions/797 ... ils-on-msv