Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5931009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:38:03+00:00 2026-05-22T14:38:03+00:00

Writing code in Brew when local interfaces are being used in it can be

  • 0

Writing code in Brew when local interfaces are being used in it can be repetitive and error prone to make it robust, i.e.:

Foo()
{
ISomeInterface* interface = NULL;
int err = ISHELL_Createnstance(…,...,&interface);

err = somethingThatCanFail();
if (AEE_SUCCESS != err)
    ISomeInterface_Release(interface);

err = somethingElseThatCanFail()
if (AEE_SUCCESS != err)
    ISomeInterface_Release(interface);

etc....

It would be quick to write an RAII class to automatically release the interface on exit from the function, but it would be specific to a particular interface (it would of course call ISomeInterface_Release in its destructor)

Is there any way of making a generic RAII class that can be used for interfaces of different types? i.e. is there a generic Release function that could be called in the RAII instead of the interface specific release, or some other mechanism?

— Edit —-
Apologies, I originally added the C++ and RAII tags to this posting which I’ve now removed.
As the answer requires Brew knowledge not C++ knowledge.
Thanks to the people who took the time to answer, I should have added more info to begin with and not added those additional tags.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T14:38:03+00:00Added an answer on May 22, 2026 at 2:38 pm

    The RAII class that calls a specified function in destructor may look like this:

    template<typename T, void (*onRelease)(T)>
    class scope_destroyer {
        T m_data;
    
    public:
        scope_destroyer(T const &data) 
            : m_data(data)
        {}
    
        ~scope_destroyer() { onRelease(m_data); }
    
        //...
    };
    

    Then you just pass a type T (e.g. a Foo*) and a function that can be called with a single parameter of type T and releases the object.

    scope_destroyer<Foo, &ISomeInterface_Release> foo(CreateFoo());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am writing code of pagination & i got an error. this is my
When writing code in Python, how can you write something next to it that
When writing code errors, warnings and notices can occur. I know the idea behind
When writing code sometimes those red error icons pop up on the left side.
When is about writing code into C++ using VS2005, how can you measure the
I am trying to writing code so that my android application can query a
After writing code that can be boiled down to the following: var size=-1; var
I sometimes find myself writing code like this: someFunc :: Foo -> Int someFunc
Instead of writing code like this every time I define a class: class Foo(object):
When writing code do you consciously program defensively to ensure high program quality and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.