Confusing code

Discussion in 'C++' started by gareth, Feb 19, 2007.

  1. gareth

    gareth Guest

    Hello all,

    I've done C before but no C++. I'm looking at the example BHO at:
    http://www.adp-gmbh.ch/win/com/bho.html and I'm a bit confused by some
    of the code:

    1. class BHO class adpbho : public IObjectWithSite, public IDispatch
    {

    Why are there two class declarations?

    2. adpbho(unsigned long cookie) : m(1), webBrowser_(0),
    connectionPointContainer(0), cookie_(cookie), document_(0) {};

    I thought : was used to show the class implemented an interface.
    What's it doing in the above line??

    Thanks

    gareth
     
    gareth, Feb 19, 2007
    #1
    1. Advertising

  2. gareth

    Gavin Deane Guest

    On 19 Feb, 14:31, "gareth" <> wrote:
    > Hello all,
    >
    > I've done C before but no C++. I'm looking at the example BHO at:http://www.adp-gmbh.ch/win/com/bho.htmland I'm a bit confused by some
    > of the code:
    >
    > 1. class BHO class adpbho : public IObjectWithSite, public IDispatch
    > {
    >
    > Why are there two class declarations?


    What is BHO? Is it a macro or something? Because I can't see any other
    way that can be anything other than a syntax error.

    > 2. adpbho(unsigned long cookie) : m(1), webBrowser_(0),
    > connectionPointContainer(0), cookie_(cookie), document_(0) {};


    That's a member initialisation list - the preferred way to initialise
    bases and members in a constructor.
    http://www.parashift.com/c -faq-lite/ctors.html#faq-10.6

    Gavin Deane
     
    Gavin Deane, Feb 19, 2007
    #2
    1. Advertising

  3. gareth

    Chris Guest

    gareth wrote:

    > 1. class BHO class adpbho : public IObjectWithSite, public IDispatch
    > {
    >
    > Why are there two class declarations?


    According to the site, this is code for a Windows DLL? My guess is that this
    isn't standard C++. Perhaps it's .NET Managed C++? MS is famous for
    altering standards in order to lock users into their products (aka. vendor
    lock-in).

    --
    Chris
     
    Chris, Feb 19, 2007
    #3
  4. gareth

    gareth Guest

    On 19 Feb, 15:29, Chris <> wrote:
    > gareth wrote:
    > > 1. class BHO class adpbho : public IObjectWithSite, public IDispatch
    > > {

    >
    > > Why are there two class declarations?

    >
    > According to the site, this is code for a Windows DLL? My guess is that this
    > isn't standard C++. Perhaps it's .NET Managed C++? MS is famous for
    > altering standards in order to lock users into their products (aka. vendor
    > lock-in).
    >
    > --
    > Chris


    There's a lot in there that seems to cause problems, even in VS.NET
    2003. I think that maybe this isn't proper code, more part pseudo code
    or maybe part of a larger project including a lot of macros (like #B,
    MB1)

    Thanks for your help

    Gareth
     
    gareth, Feb 19, 2007
    #4
  5. gareth wrote:
    > Hello all,
    >
    > I've done C before but no C++. I'm looking at the example BHO at:
    > http://www.adp-gmbh.ch/win/com/bho.html and I'm a bit confused by some
    > of the code:
    >
    > 1. class BHO class adpbho : public IObjectWithSite, public IDispatch
    > {
    >
    > Why are there two class declarations?


    I think it is just a mistake. Judging by the rest of the code the class
    is called adpbho.

    >
    > 2. adpbho(unsigned long cookie) : m(1), webBrowser_(0),
    > connectionPointContainer(0), cookie_(cookie), document_(0) {};
    >
    > I thought : was used to show the class implemented an interface.
    > What's it doing in the above line??


    You thought wrong. The : (in this case) introduces an initialiser list,
    i.e. a list of base classes and data members that are being initialised
    when the constructor executes.

    john
     
    John Harrison, Feb 19, 2007
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Will

    Confusing design considerations

    Will, Jan 22, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    411
  2. Glenn
    Replies:
    8
    Views:
    403
    Chuck Ritzke
    Apr 24, 2004
  3. Colin Howell
    Replies:
    2
    Views:
    580
    John Bokma
    Apr 25, 2010
  4. szymon.rozga

    Confusing code behavior in Rails

    szymon.rozga, Jun 21, 2005, in forum: Ruby
    Replies:
    4
    Views:
    130
    Chris McGrath
    Jun 21, 2005
  5. Replies:
    1
    Views:
    111
    Mumia W. (reading news)
    Nov 2, 2006
Loading...

Share This Page