Thread: Whats this? ( newbie question )

  1. #1
    Registered User
    Join Date
    Nov 2008

    Whats this? ( newbie question )

    I'm used of writing like this:

    int server() {}
    But here it shows a diffrent way:
    Server::Server() {}
    i'm trying too understand it, but could someone explain?

  2. #2
    Registered User
    Join Date
    Apr 2008
    This is when you get into header files and classes/structs. Basically what Server::Server means is that there is a constructor named Server inside either a class or struct named Server.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    The first one implements the method inside the body of the class.
    The second one implements it outside the class, possibly in another file.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Jan 2005
    The first might also be a free function that has nothing to do with a class, which is probably what you're used to. If you haven't learned classes yet then that's why you haven't seen the second one.

  5. #5
    Registered User
    Join Date
    Aug 2007
    Quote Originally Posted by Ashii View Post
    Server::Server() {}
    A Constructor uses the same name as the Class it is based on, hence Classname::Classname
    = Classname::Objectname

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Stupid Newbie question
    By TimL in forum C++ Programming
    Replies: 4
    Last Post: 07-22-2008, 04:43 AM
  2. C prog newbie question
    By Draginzuzu in forum C Programming
    Replies: 1
    Last Post: 02-03-2003, 05:45 PM
  3. a stupid question from a newbie
    By newcomer in forum C++ Programming
    Replies: 4
    Last Post: 01-11-2003, 03:38 PM
  4. confusion with integers (newbie question)
    By imortal in forum C Programming
    Replies: 7
    Last Post: 12-06-2002, 03:09 PM
  5. newbie class templates question
    By daysleeper in forum C++ Programming
    Replies: 2
    Last Post: 09-18-2001, 09:50 AM
Website Security Test