--- ([info]_zerg) wrote,
@ 2007-01-08 01:12:00
Previous Entry  Add to memories!  Tell a Friend!  Next Entry
Entry tags:cpp, cpp-standard, pod-types, tech

Не давно зашел разговор про то, что же считать POD типом. Я даже как то не смог, четко сказать, чего там быть не должно, единственное, о чем вспомнил - отсутствие виртуальных функций.

Вчера полез в стандарт и все что нашел:

9/4
A POD-struct is an aggregate class that has no non-static data members of type non-POD-struct, non-POD-union (or array of such types) or reference, and has no user-defined copy assignment operator and no user-defined destructor. Similarly, a POD-union is an aggregate union that has no non-static data members of type non-POD-struct, non-POD-union (or array of such types) or reference, and has no userdefined copy assignment operator and no user-defined destructor. A POD class is a class that is either a POD-struct or a POD-union.


Вот тут я нашел следующее:
As an example, the C declaration struct Fred x; does not initialize the members of the Fred variable x. To make this same behavior happen in C++, Fred would need to not have any constructors. Similarly to make the C++ version of copying the same as the C version, the C++ Fred must not have overloaded the assignment operator. To make sure the other rules match, the C++ version must not have virtual functions, base classes, non-static members that are private or protected, or a destructor. It can, however, have static data members, static member functions, and non-static non-virtual member functions.


Так все таки можно ли в POD-типе иметь конструктор или нет?



(Post a new comment)


[info]sashaandaigul
2007-01-07 08:46 pm UTC (link)
Under the hood конструктор вроде бы и и есть non-static non-virtual member function, так что да, можно.

(Reply to this)


[info]sim0nsays
2007-01-07 08:48 pm UTC (link)
Нельзя именно copy constructor, как я понимаю.

(Reply to this)(Thread)


[info]sashaandaigul
2007-01-07 08:55 pm UTC (link)
Там только сказано о перегрузке assignment operator, и ни слова о copy constructor..

(Reply to this)(Parent)


[info]sashaandaigul
2007-01-07 08:53 pm UTC (link)
А с другой стороны, как можно сказать, что класс с конструктором является аналогом С класса, если в С такая функциональность просто отсутствует?..

(Reply to this)(Thread)


[info]_zerg
2007-01-07 08:59 pm UTC (link)
ну мне интересно с точки зрения копирования POD типов, а не с точки зрения аналогов классам С

(Reply to this)(Parent)(Thread)


[info]sashaandaigul
2007-01-07 09:06 pm UTC (link)
Имхо должно работать с конструкторами. Даю примерно 9 к 1, но головой ручаться не буду :-)

(Reply to this)(Parent)


Create an Account
Forgot your login?
Login w/ OpenID
English • Español • Deutsch • Русский…