from my understanding,RAII is where u make an object out of something that performs allocation on the heap to release its resources back to the O/S? (heap allocation,opening streams,file handles,etc...)

Well RAII stands for Resource Acquisition is Initialisation. And Yes you are are right in a way: The idea is to create the object that handles your resource and let its constructor handle the acquisition and the destructor handle the freeing of it. As you know all objects that are not dynamically allocated are destroyed when they go out of scope, that means the destructor is called (automatically).

{//enter a scope
  CRAIIClass raii_obj; // create the object, acquire the resource
   // ... use the resource
   raii_obj.doSomeThing();
  
}// here the raii_obj is destroyed, the destructor is called and the resource is freed
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.