-2

This is from a CPP Source File:

class classname{

    //constructor
    classname(anotherclass *ptr);

    private:
        string firstname;
        string lastname;

};

classname::classname(anotherclass *ptr): firstname("Nathan"), lastname("Narcovy"){

    //some other definitions

}

I come from C, but I do know a bit of Object Oriented Language,
But I don't understand classname:string,string . I only remember a colon : was used for inheritance.

Kate Gregory
  • 18,808
  • 8
  • 56
  • 85
Nathan
  • 674
  • 8
  • 22
  • 3
    This is surely covered within the first chapters of any decent C++ intro book. – Luchian Grigore Jul 19 '13 at 12:12
  • 1
    I am not seeing any `classname:string,string`. However, this question is way too basic for this site. Stack Overflow assumes you did some research on yourself. – Sebastian Mach Jul 19 '13 at 12:13
  • 1
    Any answer would be meaningless unless you had some prior knowledge on C++. And then you probably wouldn't need the answer anymore. – Nbr44 Jul 19 '13 at 12:18
  • I assume you are referring to the initializer list of the classname constructor. – Pete Jul 19 '13 at 12:19
  • I think he is referring to to the way initial values are assigned in the constructor. Have a read: http://www.tutorialspoint.com/cplusplus/cpp_constructor_destructor.htm – Rob Jul 19 '13 at 12:19
  • possible duplicate of [What is this weird colon-member syntax in the constructor?](http://stackoverflow.com/questions/1711990/what-is-this-weird-colon-member-syntax-in-the-constructor) – Cubbi Jul 19 '13 at 12:33
  • It's not offtopic, but it should have been closed as a dupe of http://stackoverflow.com/questions/1711990/what-is-this-weird-colon-member-syntax-in-the-constructor as @Cubbi points out. Read that question to get your answer. – Kate Gregory Jul 19 '13 at 12:41

1 Answers1

1

This is actually how the initializer list works for constructor.

I've found this tutorial which seems to explain it decently for newcomer.

Xaqq
  • 4,308
  • 2
  • 25
  • 38