jeffrey@vermont.UUCP (Jeffrey Greenberg) (10/19/90)
zortech c++ 2.1 and gnu c++ compile the following code, which I
believe is correct. However, the sun c++ 2.0 gives the error:
"cannot initialize ::x with initializer list"
Who is right?
// the code...
class dog {
private:
int x;
};
dog x[4] = { 1,2,3,4 };
main()
{
}
// This code works if the 'int x' is public...
~
Jeffrey Greenberg, Independent Consulting
Nynex Science and Technology:
(914) 287-5523steve@taumet.com (Stephen Clamage) (10/20/90)
jeffrey@vermont.UUCP (Jeffrey Greenberg) writes: |zortech c++ 2.1 and gnu c++ compile the following code, which I |believe is correct. However, the sun c++ 2.0 gives the error: | "cannot initialize ::x with initializer list" |class dog { |private: | int x; |}; |dog x[4] = { 1,2,3,4 }; According to E&S, an aggregate type may not be initialized in this way if it contains private or protected members, among other things. The idea is that C-like structures can still be initialized in the C way, but once the aggregate looks like a C++ class, you can't do it. -- Steve Clamage, TauMetric Corp, steve@taumet.com