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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:57:10+00:00 2026-06-01T02:57:10+00:00

The three initialize methods of this class are very, very, very similar. I’d like

  • 0

The three initialize methods of this class are very, very, very similar. I’d like to see if there’s a way to chain the calls together, potentially into the method that requires both arguments. Thanks.

AudioHandler.h

class AudioHandler {

public:
    static bool Initialize(const SoundLibrary& sl);
    static bool Initialize(const Soundtrack& st);
    static bool Initialize(const SoundLibrary& sl, const Soundtrack& st);
    static void Release();
private:
    static const SoundLibrary* _sl;
    static const Soundtrack* _st;
};

AudioHandler.cpp

bool AudioHandler::Initialize(const SoundLibrary& sl) {
    if(_sl != NULL || _st != NULL) return false;

    unsigned long numVoices = 0;

    //If allegro is unable to initialize the sound drivers then return false.
    if((numVoices = detect_digi_driver(DIGI_AUTODETECT)) == 0) return false;
    if(install_sound(DIGI_AUTODETECT, MIDI_NONE, NULL) == -1) return false;
    _sl = &sl;

    return true;
}

bool AudioHandler::Initialize(const Soundtrack& st) {
    if(_sl != NULL || _st != NULL) return false;

    if(detect_midi_driver(MIDI_AUTODETECT) == 0) return false;
    if(install_sound(DIGI_NONE, MIDI_AUTODETECT, NULL) == -1) return false;
    _st = &st;

    return true;
}

bool AudioHandler::Initialize(const SoundLibrary& sl, const Soundtrack& st) {
    if(_sl != NULL || _st != NULL) return false;

    unsigned long numVoices = 0;

    if((numVoices = detect_digi_driver(DIGI_AUTODETECT)) == 0) return false;
    if(detect_midi_driver(MIDI_AUTODETECT) == 0) return false;
    if(install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, NULL) == -1) return false;

    _sl = &sl;
    _st = &st;

    return true;
}

void AudioHandler::Release() {
    _sl = NULL;
    _st = NULL;
    remove_sound();
}
  • 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-06-01T02:57:12+00:00Added an answer on June 1, 2026 at 2:57 am
    1. Leave 3rd variant only.
    2. Change references to pointers.
    3. Send NULL for the arguments you don’t need.
    4. Check for NULL before doing specific code.

    PS: in your current version, storing the address of a passed reference in the object is not a good idea.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a particular way to initialize an IList<T> ? This does not seem
unordered_map<std::string, std::string>* Accounts; I have this code up there to initialize from a pointer,
Is there any simple way how to initialize String in Objective-C with int such
Is there are an easy way to initialize byte array from portion of existing
Is there any way to tell GCC to not initialize a particular global array
As we all known, when we call a constructor of a class like this:
I'd like to have a little php module. This module would have methods that
I'm creating a DirectX 11 helper class that looks kind of like this: #import
I have a static Command class like this (but with many more commands): class
Inside the initialize() function there is a jQuery each loop. Inside that loop is

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.