I suppose you have code similar to the following example:
#include <iostream>
struct foo {
private:
struct bar {
void barbar() { std::cout << "hello";}
};
public:
bar foobar() { return bar{}; }
};
int main() {
foo f;
foo::bar x = f.foobar();
x.barbar();
}
It has an error:
<source>: In function 'int main()':
<source>:13:10: error: 'struct foo::bar' is private within this context
13 | foo::bar x = f.foobar();
| ^~~
<source>:4:15: note: declared private here
4 | struct bar {
| ^~~
because bar
is private in foo
. However, that doesnt mean that you cannot use it outside of foo
. You can use auto
:
int main() {
foo f;
auto x = f.foobar();
x.barbar();
}
Or decltype
:
int main() {
foo f;
using bar_alias = decltype(f.foobar());
bar_alias x = f.foobar();
x.barbar();
}
You cannot access the name DataType
but you can use auto
and you can get an alias for the type. This also works for a std::vector<DataType>
, only some more boilerplate would be required to get your hands on DataType
directly.