1

Possible Duplicate:
What are Aggregates and PODs and how/why are they special?

What kind of constructors can structs in C++11 have to keep this struct as POD?

Only initializer-list acceptable? Or maybe there are no any restrictions?

Community
  • 1
  • 1
FrozenHeart
  • 18,778
  • 30
  • 107
  • 223

1 Answers1

1

You need a defaulted default constructor so that it is trivial:

struct pot
{
    constexpr pot() noexcept = default;

    pot(int a, float b) : x(a), y(b) { }

    int x;
    float y;
};

The constexpr and noexcept are optional, but we might as well.

Usage:

pot p;         // OK
pot q(1, 1.5); // also OK
Kerrek SB
  • 447,451
  • 88
  • 851
  • 1,056