I want to hide n_platforms from client *.cpp files. But I want getNumberOfPlatforms() remain inline.
How can I do this?
I thought this: (but I cannot use using namespace OpenCL anymore)
I like chameleon's solution. That should be enough to discourage anyone from mucking around with n_platforms, although it doesn't technically do anything to restrict access to n_platforms. Still beats the heck out of trying to do something like:
Header:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
namespace OpenCL
{
class info {
staticunsignedint n_platforms;
public:
staticunsignedint platforms() { return info::n_platforms; }
friendclass info_ ;
};
inlineunsignedint getNumberOfPlatforms() { return info::platforms(); }
};
// user code: unsigned n = OpenCL::getNumberOfPlatforms() ;
Implementation file:
1 2 3 4 5 6 7 8 9 10 11 12
namespace OpenCL {
class info_
{
public:
staticunsignedint& n_platforms ;
};
}
unsignedint OpenCL::info::n_platforms = 0;
unsignedint& OpenCL::info_::n_platforms = OpenCL::info::n_platforms ;
// use info_::n_platforms in the implementation code.
which is the best I could figure out. =/
If it were me though, I'd probably just forgo the inline function. This isn't code that's likely to end up in a time critical loop somewhere.