Thread: Are these parameters??

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    269

    Are these parameters??

    There are some weird lines of code in this .cpp file

    Code:
    VideoInput::VideoInput(): 
        capture(cvCaptureFromCAM(0)), framecount(0),
    	frame(cvQueryFrame(capture)), size(cvSize(frame->width, frame->height))
    {}
    
    VideoInput::VideoInput(const char* filename):
        capture(cvCaptureFromFile(filename)), framecount(0),
        frame(cvQueryFrame(capture)), size(cvSize(frame->width, frame->height)) 
    {}
    What exactly is:

    capture(cvCaptureFromFile(filename)), framecount(0),
    frame(cvQueryFrame(capture)), size(cvSize(frame->width, frame->height))

    It's not parameters? They're just function calls stringed together via comma's....

  2. #2
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    No, they're part of a constructor initialisation lists. I.e. those are constructor calls for some of its members.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  3. #3
    C++ Junkie Mozza314's Avatar
    Join Date
    Jan 2011
    Location
    Australia
    Posts
    174
    I think part of why it's confusing is the way it's written too. I would write it like this:

    Code:
    VideoInput::VideoInput()
    :
        capture(cvCaptureFromCAM(0)),
        framecount(0),
        frame(cvQueryFrame(capture)),
        size(cvSize(frame->width, frame->height))
    {
    }
    
    VideoInput::VideoInput(const char* filename)
    :
        capture(cvCaptureFromFile(filename)),
        framecount(0),
        frame(cvQueryFrame(capture)),
        size(cvSize(frame->width, frame->height)) 
    {
    }
    In particular I think it's good for that ':' to appear on its own line to emphasise that this is an unusual block of code. Written like that even a newbie should be able to see that ':' and think "oh, well this is just a structure I haven't seen before". If the ':' is on the end of the line above it can be easily missed and you see the unusual nature of the code below and you have to backtrack to see the ':' to confirm that it's an initialisation list.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with C Program Hw Parameters
    By 123456tacos in forum C Programming
    Replies: 3
    Last Post: 03-11-2011, 07:27 AM
  2. Compiling C in Visual Studio 2005
    By emanresu in forum C Programming
    Replies: 3
    Last Post: 11-16-2009, 04:25 AM
  3. Replies: 6
    Last Post: 07-21-2008, 06:04 AM
  4. function with variable number of parameters
    By mikahell in forum C++ Programming
    Replies: 3
    Last Post: 07-23-2006, 03:35 PM
  5. Additional parameters for operator delete
    By darksaidin in forum C++ Programming
    Replies: 0
    Last Post: 09-21-2003, 11:46 AM