I have the following classes:
template<typename T, size_t Level>
class Foo
{
friend class Foo<T, Level + 1>;
typedef std::unique_ptr<T> ElmPtr;
typedef std::unique_ptr<Foo<ElmPtr, Level - 1>> NodePtr;
public:
Foo() {
// no errors
auto c = children;
}
Foo(int n) {
// !!! compiler error !!!
auto c = children;
}
std::array<NodePtr, 4> children;
};
template<typename T>
class Foo<T, 0>
{
friend class Foo<T, 1>;
public:
Foo() {}
};
Foo<int, 1> foo1;
I get the following error:
error C2248: 'std::unique_ptr<_Ty>::unique_ptr' : cannot access private member declared in class 'std::unique_ptr<_Ty>'
Why? How can I fix this problem?
Aucun commentaire:
Enregistrer un commentaire