[cfe-dev] Error Accessing friend Methods
Uri Mann via cfe-dev
cfe-dev at lists.llvm.org
Sun Dec 13 07:52:24 PST 2015
I have the following code:
// header1.h
class Infc;
template<typename Type>
struct Struct {
Infc* _infc;
Struct(Infc* infc) : _infc(infc) {}
~ Struct() { _infc->destroy(this); }
};
// header2.h
template<typename> friend struct Struct;
class Infc {
public:
virtual void create() = 0; // For everyone
private:
template<typename> friend struct Struct;
virtual void destroy(void* _this) = 0; // Only for friends
};
// source.cpp
#include "header1.h"
#include "header2.h"
Infc* g_infc;
void f() {
Struct s(g_infc);
}
CLANG issue the following error:
1> In file included from source.cpp:
1>header1.h: error : 'destroy' is a private member of 'Infc'
1> ~ Struct() { _infc->destroy(this); }
1> ^
1> header2.h : note: declared private here
1> virtual void destroy(void* _this) = 0;
1> ^
What am I doing wrong? Why is the friendship not recognized?
Many thanks in advance.
-Uri
More information about the cfe-dev
mailing list