Thread: constructor???

  1. #1
    ... arjunajay's Avatar
    Join Date
    May 2005
    Posts
    203

    Talking constructor???

    I found this code in a book.
    Code:
    class Binary_Search_Tree{
        struct Node;
        Node * _root;
        //blah
        //blah
    };
    
    struct Binary_Search_Tree::Node{
        Type _;
        Node* _left;
        Node* _right;
        Node(Type = Type(), Node* =0, Node* = 0);
    };
    1.)What does that line mean? Is it a constructor for 'struct's'?
    I've never heard of constructors for structs.
    2.)More over throughout the whole program, I dont see any
    Code:
    template<class Type>
    Is it correct?

  2. #2
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    'Type' better be a typedef or class somewhere. The logical choice would've been to make it a template parameter as you suggested, but apparently, they didn't do that.

    Structs can have constructors, destructors, private member data, virtual functions, inherit from one another, etc.

    The only difference between classes and structs is their default access. That is:
    Code:
    struct foo1 {
       int bar; // This is public
    };
    
    class foo2 {
       int bar; // This is private
    };
    That is the only difference.
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    Minor clarification: these are the only differences:
    Code:
    struct foo1 : base { // base is inherited publicly
      int bar; // This is public
    };
     
    class foo2 : base { // base is inherited privately
      int bar; // This is private
    };

  4. #4
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    Right... Thanks.

    I always explicitly state public/private inheritance, and never think about it.

    Cheers
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  5. #5
    ... arjunajay's Avatar
    Join Date
    May 2005
    Posts
    203
    cool... I never knew this...
    Structs can have constructors, destructors, private member data, virtual functions, inherit from one another, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 06-10-2008, 08:38 PM
  2. C++ have a constructor call another constructor
    By QuestionC in forum C++ Programming
    Replies: 4
    Last Post: 05-17-2007, 01:59 AM
  3. Replies: 3
    Last Post: 03-26-2006, 12:59 AM
  4. Need help in classes
    By LBY in forum C++ Programming
    Replies: 11
    Last Post: 11-26-2004, 04:50 AM
  5. Constructor with Parameter not Firing
    By BillBoeBaggins in forum Windows Programming
    Replies: 4
    Last Post: 08-26-2004, 02:17 PM