Whats this? ( newbie question )

This is a discussion on Whats this? ( newbie question ) within the C++ Programming forums, part of the General Programming Boards category; I'm used of writing like this: Code: int server() {} But here it shows a diffrent way: Code: Server::Server() {} ...

  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    8

    Whats this? ( newbie question )

    I'm used of writing like this:

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

  2. #2
    Registered User
    Join Date
    Apr 2008
    Posts
    122
    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,547
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    7,318
    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
    Location
    U.K.
    Posts
    148
    Quote Originally Posted by Ashii View Post
    Code:
    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

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