dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Help with syntax for the class constructor definition

  1. #1
    Join Date
    May 2008
    Posts
    1

    Help with syntax for the class constructor definition

    Hello,

    I am trying to understand somebody else's code. I was wondering if somebody could
    help me understand what the constructor definition is doing in this example. I know that the '::' allows you to access and define the methods of a class, but what does the ':' after that do?

    If it helps, SOUNDSPOTTER_INITIALIZERS is a macro and I include its definition at the bottom.

    Thanks!
    -Pablo

    From Soundspotter.cpp
    ============================================

    SoundSpotter::SoundSpotter() : SOUNDSPOTTER_INITIALIZERS
    {

    hammingWin = new ss_sample[WindowLength];
    makeHammingWin();
    hammingWin2 = new ss_sample[WindowLength];
    makeHammingWin2();
    resizeShingles(shingleSize);

    // Construct transform coefficients
    makeLogFreqMap();
    makeDCT();

    maxASB=dctN;
    setBasisWidth(dctN);

    inShingle = new SeriesOfVectors(dctN, MAX_SHINGLE_SIZE);

    // FFTW memory allocation
    fftIn = (double*) fftw_malloc(sizeof(double)*fftN);
    fftComplex = (fftw_complex*) fftw_malloc(sizeof(fftw_complex)*fftOutN);
    fftPowerSpectrum = new double[fftOutN];
    cqtOut = new double[cqtN];
    dctOut = new ss_sample[dctN];

    assert(fftIn && fftComplex && fftPowerSpectrum && cqtOut && dctOut && inShingle);

    // FFTW plan cache
    fftwPlanFile = fopen(FFTWPLAN_FILENAME, "w");
    int fftwResult=0;
    if(fftwPlanFile)
    fftwResult=fftw_import_wisdom_from_file(fftwPlanFile);
    fftwPlan = fftw_plan_dft_r2c_1d(fftN, fftIn, fftComplex, FFTW_PATIENT);
    if(!fftwResult && fftwPlanFile){
    fftw_export_wisdom_to_file(fftwPlanFile);
    }
    fclose(fftwPlanFile);


    } // end of constructor


    From Soundspotter.h
    ===========================================
    #define SOUNDSPOTTER_INITIALIZERS sampleRate(44100), \
    maxF(23*7200), \
    bufLen(0), \
    MAX_SHINGLE_SIZE(128), \
    sourceShingles(0), \
    inShingle(0), \
    queueSize(20), \
    minASB(0), \
    MAX_Queued(1000), \
    fftN(16384), \
    fftOutN(fftN/2+1), \
    bpoN(12), \
    WindowLength(2048), \
    Radius(0.0), \
    shingleSize(4), \
    EnvFollow(0), \
    soundSpotterStatus(STOP), \
    ENV_THRESH(0.001)


    #endif

  2. #2
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,762

    Re: Help with syntax for the class constructor definition

    I know that the '::' allows you to access and define the methods of a class, but what does the ':' after that do?
    It marks the start of the initialisation list which is used to initialise the members of the object (as opposed to assigning to them in the body of the constructor).
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  3. #3
    Join Date
    Aug 2002
    Location
    Cluj-Napoca,Romania
    Posts
    3,496

    Re: Help with syntax for the class constructor definition

    To add to what laserlight already stated, here is a discussion on what the constructor initialization lists are and why they should be used.

    http://www.parashift.com/c++-faq-lit....html#faq-10.6
    Har Har

  4. #4
    Join Date
    Apr 1999
    Location
    Altrincham, England
    Posts
    4,470

    Re: Help with syntax for the class constructor definition

    And can I just add that, if that code came to me for a code review, it would bounce back marked "rewrite" PDQ.
    Correct is better than fast. Simple is better than complex. Clear is better than cute. Safe is better than insecure.
    --
    Sutter and Alexandrescu, C++ Coding Standards

    Programs must be written for people to read, and only incidentally for machines to execute.

    --
    Harold Abelson and Gerald Jay Sussman

    The cheapest, fastest and most reliable components of a computer system are those that aren't there.
    -- Gordon Bell


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)