|
-
June 13th, 2012, 12:40 PM
#1
why is inner class only accessible to template specialization if code is inlined?
Hi:
I've got this oddball problem in a much larger program which is replicated by the following code in VS 2010:
DemonstrateIssue.h:
Code:
#ifndef _PROBLEM_CODE_H_INCLUDED_
#define _PROBLEM_CODE_H_INCLUDED_
class CWidgetProcessorBaseClass
{
protected: struct XWidget;
private : class XWidgetInterClassStorage;
};
#endif// _PROBLEM_CODE_H_INCLUDED_
DemonstrateIssue.cpp:
Code:
#include "DemonstrateIssue.h"
#include <vector>
usingnamespace std;
#define WHY_WONT_THIS_COMPILE
class CWidgetProcessorBaseClass::XWidgetInterClassStorage
{
template <class T> struct XThreadData
{
XThreadData(void);
~XThreadData(void);
int a;
char b;
vector<T *> c;
};
template <> struct XThreadData<XWidget>
{
# ifdef WHY_WONT_THIS_COMPILE
XThreadData(void);
~XThreadData(void);
# else
XThreadData(void) : a(5), b('x')
{
d.push_back(6);
}
~XThreadData(void)
{
int x = 5;
}
# endif
int a;
char b;
vector<XWidget *> c;
vector<int > d;
};
};
template <class T>
CWidgetProcessorBaseClass::XWidgetInterClassStorage::XThreadData<T>::
XThreadData(void)
: a(5), b('x')
{
}
template <class T>
CWidgetProcessorBaseClass::XWidgetInterClassStorage::XThreadData<T>::
~XThreadData(void)
{
int x = 0;
}
#ifdef WHY_WONT_THIS_COMPILE
CWidgetProcessorBaseClass::XWidgetInterClassStorage::XThreadData<CWidgetProcessorBaseClass::XWidget>::
XThreadData(void)
: a(5), b('x')
{
d.push_back(6);
}
CWidgetProcessorBaseClass::XWidgetInterClassStorage::XThreadData<CWidgetProcessorBaseClass::XWidget>::
~XThreadData(void)
{
int x = 0;
}
#endif
void main(void)
{
}
Result:
1>ClCompile:
1> DemonstrateIssue.cpp
1>c:\users\GeoRanger\documents\visual studio 2010\projects\demonstrateissue\demonstrateissue.cpp(59): error C2248: 'CWidgetProcessorBaseClass::XWidget' : cannot access protected struct declared in class 'CWidgetProcessorBaseClass'
1> c:\users\GeoRanger\documents\visual studio 2010\projects\demonstrateissue\demonstrateissue.h(6) : see declaration of 'CWidgetProcessorBaseClass::XWidget'
1> c:\users\GeoRanger\documents\visual studio 2010\projects\demonstrateissue\demonstrateissue.h(5) : see declaration of 'CWidgetProcessorBaseClass'
1>c:\users\GeoRanger\documents\visual studio 2010\projects\demonstrateissue\demonstrateissue.cpp(64): error C2248: 'CWidgetProcessorBaseClass::XWidget' : cannot access protected struct declared in class 'CWidgetProcessorBaseClass'
1> c:\users\GeoRanger\documents\visual studio 2010\projects\demonstrateissue\demonstrateissue.h(6) : see declaration of 'CWidgetProcessorBaseClass::XWidget'
1> c:\users\GeoRanger\documents\visual studio 2010\projects\demonstrateissue\demonstrateissue.h(5) : see declaration of 'CWidgetProcessorBaseClass'
1>
1>Build FAILED.
However, if you comment out the #define it will compile just fine. It also compiles if you change the header file's line "protected: struct XWidget" to "public: struct XWidget", but that is not an acceptable workaround in the real program.
Does anyone know why this is inconsistent? It seems like if the inline version compiles, then so should the non-inline, and likewise if the non-inline can't compile, then the inline shouldn't be able to either.
Thanks, 
GeoRanger
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|