Like Tree4Likes
  • 3 Post By tabstop
  • 1 Post By cyberfish

What is wrong with the constructor initialization?

This is a discussion on What is wrong with the constructor initialization? within the C++ Programming forums, part of the General Programming Boards category; .cpp Code: bloomfilter::bloomfilter(int m, long long p, int c):primenumber(p), tablesize(m), hashfunctions(c), vector <int> A(c), vector <int> B (c){ } Code: ...

  1. #1
    Registered User
    Join Date
    Sep 2012
    Posts
    86

    What is wrong with the constructor initialization?

    .cpp
    Code:
    bloomfilter::bloomfilter(int m, long long p, int c):primenumber(p), tablesize(m), hashfunctions(c), vector <int> A(c), vector <int> B (c){
    }
    
    Code:
    .h
    public: bloomfilter(int, long long, int);
    It saying overloaded, but my parameters are declared.

  2. #2
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    1,191
    I thin you have to construct in the same order your arguments are declared.

  3. #3
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Why do your last two variables in the initialization list have types?
    King Mir, cyberfish and iMalc like this.

  4. #4
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,183
    Quote Originally Posted by MutantJohn View Post
    I thin you have to construct in the same order your arguments are declared.
    Members are initialized in the order they are declared in the class. The order of initialization list is irrelevant, though most compilers will warn you if it differs from the order they are declared.
    kmdv likes this.

  5. #5
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    Quote Originally Posted by cyberfish View Post
    Members are initialized in the order they are declared in the class. The order of initialization list is irrelevant, though most compilers will warn you if it differs from the order they are declared.
    I would say - some compilers would do it, since it could misguide the programmer reading the code to believe wrong order of initializations based on initializes list.
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  6. #6
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    1,191
    Quote Originally Posted by cyberfish View Post
    Members are initialized in the order they are declared in the class. The order of initialization list is irrelevant, though most compilers will warn you if it differs from the order they are declared.
    Ah, thank you for correcting me. I knew it was something like that where if you weren't using an explicit constructor (where you use curly brackets in lieu of : ) the order mattered, I just wasn't sure on the order of what.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Constructor Initialization/operator overloading
    By MattJ812 in forum C++ Programming
    Replies: 3
    Last Post: 12-25-2010, 12:24 PM
  2. Constructor Initialization
    By Kane in forum C++ Programming
    Replies: 5
    Last Post: 04-05-2007, 07:12 AM
  3. Replies: 9
    Last Post: 10-26-2005, 07:29 AM
  4. Something wrong in initialization?
    By Shadow12345 in forum C++ Programming
    Replies: 1
    Last Post: 04-26-2002, 01:42 PM
  5. Class constructor with initialization
    By WebSnozz in forum C++ Programming
    Replies: 1
    Last Post: 11-20-2001, 04:31 PM

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