Consider the following code:
#include <iostream>
using namespace std;
class Outer {
struct Inner {
int num;
};
public:
static Inner GetInner() {
return Inner{-101};
}
};
template <typename Dummy>
void func2(Outer::Inner inner, Dummy = Dummy()) {
cout << inner.num << endl;
}
int main() {
func2<int>(Outer::GetInner());
return 0;
}
How can I use a type argument Outer::Inner, which is a private type, in a function that is not a member func2? ' func1rightly complains when I try to use it with the following error message:
prog.cpp: In function 'void func1(Outer::Inner)':
prog.cpp:5:9: error: 'struct Outer::Inner' is private
struct Inner {
^
prog.cpp:15:19: error: within this context
void func1(Outer::Inner inner) {
^
I am using g ++ 4.8.2 on ubuntu, but I also see this on gcc-4.9.2 (at www.ideone.com)
You can try the code here: Ideone
source
share