I’d like to create a class template, ptrs_and_refs_only<T>, which only may be manipulated through pointers and references. In other words, values of this type should be disallowed, except for things declared as friends of the type.
Specifically, I’d like the compiler to issue an error if it encounters this type used as a function parameter:
void foo(ptrs_and_refs_only<int> x); // error!
void bar(ptrs_and_refs_only<int> &x); // ok
void baz(ptrs_and_refs_only<int> *x); // ok
I know that I can make ptrs_and_refs_only<T>‘s copy constructor private, but that doesn’t seem to cause an error in this code:
template<typename T>
class ptrs_and_refs_only
{
private:
ptrs_and_refs_only() {}
ptrs_and_refs_only(const ptrs_and_refs_only &) {}
};
void foo(ptrs_and_refs_only<int> x) {}
int main()
{
return 0;
}
Is this behavior possible?
Here’s a skeleton, but I don’t know if it’ll be adaptable to what you need:
You’d still need to find a way to make the class constructible for certain client classes.