copy-constructor

C++ Qt Reflection with Copy and Assignment

一曲冷凌霜 提交于 2019-12-23 09:05:28
问题 As the QObject documentation and many others explain, a QObject has an identity and thus hides its copy constructor and assignment operator. However, I'm not deriving from QObject for its dynamic properties feature or the signals/slots feature. I only want reflection , or the ability to access Foo::staticMetaObject . class Foo : public QObject { Q_OBJECT Q_ENUMS(Color) public: enum Color { Blue, Red, Pink }; private: Color color; }; Q_DECLARE_METATYPE(Foo::Color) I then can't copy Foo with:

Is there a good way to copy a Gtk widget?

只谈情不闲聊 提交于 2019-12-23 08:03:21
问题 Is there a way, using the Gtk library in C, to clone a Gtk button (for instance), and pack it somewhere else in the app. I know you can't pack the same widget twice. And that this code obviously wouldn't work, but shows what happens when I attempt a shallow copy of the button: GtkButton *a = g_object_new(GTK_TYPE_BUTTON, "label", "o_0", NULL); GtkButton *b = g_memdup(a, sizeof *a); gtk_box_pack_start_defaults(GTK_BOX(vbox), GTK_WIDGET(b)); There is surrounding code which creates a vbox and

C++ Deep Copy Vector Pointer Object

自作多情 提交于 2019-12-23 07:00:54
问题 I have a class called Heap that is a Vector of pointers to HeapItem objects vector<HeapItem*> myHeap; I want to create a deep copy of Heap so that I can delete all the items in the copy without affecting the original Heap. EX: OriginalHeap = new Heap(); OriginalHeap.Insert(HeapItem1); OriginalHeap.Insert(HeapItem2); OriginalHeap.Insert(HeapItem3); CopyHeap = OriginalHeap; CopyHeap.deleteMin(); print(OriginalHeap); print(CopyHeap); Output: OriginalHeap = HeapItem1,HeapItem2,HeapItem3 CopyHeap

Implementation supplied copy constructor and assignment operator

拟墨画扇 提交于 2019-12-22 11:26:41
问题 I have a small confusion regarding the situations where the implementation (compiler) will not supply the copy constructor and the copy assignment operator. When we declare the copy ctor and/or copy assignment operator in our class. Some says when we derive from a class which has a private copy ctor and/or copy assignment operator. I am a little confused about the second situation, is the second situation is precisely. a) The implementation will not declare them for you, so you will get a

C++ constructor calling and object creation

£可爱£侵袭症+ 提交于 2019-12-22 08:37:23
问题 class Test{ public : int x; Test() { x = 0; cout<<"constructor with no arguments called"<<endl; } Test(int xx) { x = xx; cout<<"constructor with single int argument called"<<endl; } }; int main() { Test a(10); Test aa = 10; } output: Program compiles and outputs constructor with single int argument called constructor with single int argument called But now class Test{ public : int x; Test() { x = 0; cout<<"constructor with no arguments called"<<endl; } Test(int xx) { x = xx; cout<<

how can I find where a C++ copy constructor is being USED via a compile error?

强颜欢笑 提交于 2019-12-22 07:41:51
问题 In short: is there some way I can modify a class definition such that it fails to compile at the point of use of a copy constructor no matter where it's used? I have a very large project and was cleaning up some class definitions. There's a class that I explicitly don't want to use copy constructors on (let's ignore why that is for the sake of this discussion), and in the interest of safety, I figured I'd just define the copy constructor as private and not actually implement it... that way it

Is the object copied or not when RVO/NRVO kicks in?

喜欢而已 提交于 2019-12-22 06:49:19
问题 I can't get my head around RVO (and NRVO) definition because of multiple questions like this one that to me look assuming that RVO omits a copy constructor. Now according to 12.8.15 In such cases, the implementation treats the source and target of the omitted copy operation as simply two different ways of referring to the same object, and the destruction of that object occurs at the later of the times when the two objects would have been destroyed without the optimization. Which looks like it

C++: Is default copy constructor affected by presence of other constructors and destructor?

末鹿安然 提交于 2019-12-22 04:15:15
问题 As we know, if any constructor is declared (copy constructor included), default constructor (the one that takes no arguments) is not implicitly created. Does the same happen with a default copy constructor (the one that performs shallow copy of an object)? Also, does the presence of destructor affect this anyhow? 回答1: The answers here are correct but not complete. They are correct for C++98 and C++03. In C++11 you will not get a copy constructor if you have declared a move constructor or move

member copying of class

◇◆丶佛笑我妖孽 提交于 2019-12-21 19:56:39
问题 While learning the concept of "copying members", the book gives the following statement. In addition, a default assignment cannot be generated if a nonstatic member is a reference, a const,or a user-defined type without a copy assignment. I do not quite understand what does this statement really want to deliver? Or which kind of scenario does this statement refer to? Thanks. 回答1: This statement has to do with the compiler automatically generating the default assignment operator function for a

implementing a copy constructor

人盡茶涼 提交于 2019-12-21 17:42:26
问题 I have the following class definition and it needs a copy constructor so deep copies are made to copy the raw pointers. Can anybody advice on how to best do this? Using xerces-c++ for XML class XMLDocument { private: typedef std::vector<XML::XMLNode> v_nodes; public: XMLDocument::XMLDocument(); XMLDocument::XMLDocument(const XMLDocument& copy); XMLDocument::~XMLDocument(); XMLDocument& operator=(XMLDocument const& rhs); void CreateDocument(const std::string& docname); void AddChildNode