-2

I have this code:

Kuvio::Kuvio(Piste& paikka, string& nimi) : paikka(paikka), nimi(nimi) {}

Do not care about the words. I'd like to know is that a function definition, a function call or what? I'm not familiar with C++.

Tower
  • 98,741
  • 129
  • 357
  • 507
  • 4
    I suggest you pick up a [good book](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list), C++ is not easy to parse (for humans or compilers). – Mat Oct 03 '11 at 08:04

3 Answers3

6

It's a definition of the constructor of class Kuvio using an initialization list.

It's almost equivalent to:

Kuvio::Kuvio(Piste& paikka, string& nimi) 
{
   paikka = paikka; 
   nimi = nimi; 
} 

, which is redundant. In general however, the difference is that the members are not initialized two times, as it would happen with my snippet of code, but only once in the initialization list.

Luchian Grigore
  • 253,575
  • 64
  • 457
  • 625
2

Function definition, constructor of class Kuvio.

MSalters
  • 173,980
  • 10
  • 155
  • 350
2

It's defining the constructor of class Kuvio. The part between : and {} is an initializer list - it takes paikka and nimi member variables and initializes them with the values of paikka and nimi parameters.

jrok
  • 54,456
  • 9
  • 109
  • 141