In need of some help

This is a discussion on In need of some help within the C++ Programming forums, part of the General Programming Boards category; Hi all, I'm relatively new to C++ programming..... Can some please explain to me what the following lines of code ...

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    51

    Question In need of some help

    Hi all, I'm relatively new to C++ programming.....
    Can some please explain to me what the following lines of code exactly do?

    //I know this is a constructor but the syntax is confusing...
    THMT::THMT(int ns, int nc, int nl, bool zm)
    :M(ns), nCh(nc), nLev(n1), zeromean(zm),
    model_trans(nLev, matrix<double>(M,M),
    model_mean(nLev, vector<double>(M)),
    model_stdv(nLev, vector<double>(M))
    {
    rnd_init_model();
    }

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    That's an initializer list
    Code:
    MyClass :: MyClass ( int var1, int var2, int var3 ) : 
    member1 ( var1 ), member2 ( var2 ), member3 ( var3 )
    {
      // Initialize class members
    }
    is equivalent to
    Code:
    MyClass :: MyClass ( int var1, int var2, int var3 )
    {
      // Initialize class members
      member1 = var1;
      member2 = var2;
      member3 = var3;
    }
    Initializer lists tend to be more efficient and compact, but the syntax is confusing to some.

    -Prelude
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Mar 2002
    Posts
    51

    Talking

    Thanks for the reply!

    Appreciate it!

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21