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 259275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T22:15:01+00:00 2026-05-11T22:15:01+00:00

This seems to be a trivial question but I got hung on it for

  • 0

This seems to be a trivial question but I got hung on it for a few hours now (maybe too much Java killed my C++ braincells).

I have created a class that has the following constructor (i.e. no default constructor)

VACaptureSource::VACaptureSource( std::string inputType, std::string inputLocation ) {
    if( type == "" || location == "" ) {
    throw std::invalid_argument("Empty type or location in VACaptureSource()");
}
type = inputType;
location = inputLocation;

// Open the given media source using the appropriate OpenCV function.
if( type.compare("image") ) {
    frame = cvLoadImage( location.c_str() );
    if( !frame ) {
        throw std::runtime_error("error opening file");
    }
}
else {
    throw std::invalid_argument("Unknown input type in VACaptureSource()");
}

}

When I want to create an instance, I use

    // Create input data object
try {
    VACaptureSource input = VACaptureSource("image", "/home/cuneyt/workspace/testmedia/face_images/jhumpa_1.jpg");
}
catch( invalid_argument& ia ) {
    cerr << "FD Error: " << ia.what() << endl;
    usage(argv[0]);
}
catch( runtime_error& re ) {
    cerr << "FD Error: " << re.what() << endl;
    usage(argv[0]);
}

However, in this case the instance is local to this block and I can’t refer to it anywhere else. On the other hand, I can’t say

VACAptureSource input;

at the beginning of the program since there’s no default constructor.

What is the correct way to do this?

Thanks!

  • 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-11T22:15:02+00:00Added an answer on May 11, 2026 at 10:15 pm

    What about using a pointer (or some RAII version thereof)?

    VACaptureSource* input = NULL;
    
    try {
        input = new VACaptureSource(...);
    } catch(...) {
        //error handling
    }
    
    //And, of course, at the end of the program
    delete input;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This seems like such a trivial question to ask, but it's been vexing me
This seems to me to be a trivial question, but I've had a lot
Seems a trivial question, but surprisingly, found only some solutions like this one ,
This seems to be a trivial question, but this issue really, really drives me
This seems like a trivial R question, but I didn't find any convincing solution.
This seems like a a trivial question, but I'm lost. In this example character
I know this seems to be a trivial question but I could not find
This may seem a trivial question, but it's one that's bothered me a lot
This might seem like a trivial question, but I'm a bit muddled in my
This question may seem trivial, but I hope you won't ignore it. Before destroying

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.