I am implementing a class that uses the RAII idiom. Obviously this class should only be created on the stack, so I'm looking for a way to provide this.
This is not RAII. RAII is initialized during construction and deinitialization in destructors. RAII are the resources you control (for example, data members), not the lifetime of the "parent" object. Users of your type then reapply RAII to control the lifetime of what they secrete. For example, you can dynamically highlight std :: vector, although the vector uses RAII to make sure that every element that it "owns" is cleared.
My question is, does it have any side effects that are not straightforward to see?
Yes, you are forbidden to use another action (at least with regard to RAII) to use your type.
void example() { shared_ptr<T> p (new T());
Is this a good approach to force an instance on the stack?
What are you trying to prevent? What is a use case? Anyone who uses the new with your type either 1) knows what he is doing and needs it, or 2) it will terribly ruin the resource management no matter what you do. You interfere with those in # 1, not helping those in # 2, trying to secure this.
This is another way to state what Steve said:
This class, obviously, should only be created on the stack, so I'm looking for a way to provide this.
If this is obvious, why should this be done?
If users blindly use "new T ()", what makes you think that they will not blindly use ":: new T ()"?
The goal is to make it easy to configure to set up the framework and put it in a ready-to-use state without having to create 10 objects in the client code.
#include <framework> int main() { framework::Init init; // Do stuff. }
Use this or something very close to it, which is noticeable in the examples of your documents.