×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Initializing classes as POD

Initializing classes as POD

Initializing classes as POD

(OP)
Here's a strange one that got me foxed for a while - only happens on VC6.  OK on VC2003 and gcc.  I don't really know whether it is legal to initialize a class as POD or not.

CODE

class Legal
{
public:
    int tom;
    int dick;
    int harry;

private:
    void DoSomething ();
};

Legal ll = { 1, 2, 3 };

int main ()
{
    return 0;
}
Comes up with error C2552: 'll' : non-aggregates cannot be initialized with initializer list
To fix it, comment out private.

RE: Initializing classes as POD

It is legal to initialize a class (or struct) as a POD as long as the class has:
  • No user-declared constructors
  • No private or protected non-static data members
  • No base classes
  • No virtual functions
I'm guessing that's a bug in VC++ 6.0 that considers the private member function to conflict with the second part in the list. The correct interpretation appears to be that only data members (members that can hold an actual value) are subject to that restriction, not member functions.

So your code should be legal according to the standard. Note that it also compiles with Comeau online.

RE: Initializing classes as POD

(OP)
Thanks for the confirmation.

I'd like the client to move to a more up to date compiler so we can at least drop the pragma warning(disable:4768) and have a better IDE but they're set on VC6 SP5 (note even SP6!) so we have to live with bugettes like these for the next 3 years.  So much for state-of-the-art technology companies!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close