[cfe-dev] Error Accessing friend Methods
Richard Smith via cfe-dev
cfe-dev at lists.llvm.org
Sun Dec 13 08:18:53 PST 2015
Your code example has several other errors in it, can you provide us with
the actual code that produced the reported error?
On Dec 13, 2015 10:52 AM, "Uri Mann via cfe-dev" <cfe-dev at lists.llvm.org>
wrote:
> 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
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20151213/8cbfa460/attachment.html>
More information about the cfe-dev
mailing list