Mit einem Konstruktor in einer Funktion aufrufen?

Ich habe Suche eine Weile für eine gute Erklärung, warum/warum nicht das verwenden der struct Konstruktor als argument function legal ist. Kann mir jemand eine zur Verfügung?

//Begin simple illustrative example C++ program    
#include<vector.h>

struct Item  
{  
  Item(double data, const int lead)
  : m_grid(data), m_lead(lead) {}

  double m_grid;
  int m_lead;
};

int main()
{
  double img = 0.0;
  int steps = 5;
  std::vector<Item> images;
  for (int i = 0; i < steps; i++)
  {
    img += 2.0;
    images.push_back(Item(img,i));
  }
  return 0;
}

War ich unter dem Eindruck, einen Konstruktor hat weder Rückgabetyp noch die Aussage...

  • Ist es C++? Bitte wählen Sie Ihre Sprache.
  • Sorry, ja, C++
InformationsquelleAutor Evan | 2011-03-10
Schreibe einen Kommentar