initialization

Is there a way to disable copy elision in c++ compiler

旧城冷巷雨未停 提交于 2020-01-13 17:58:13
问题 In c++98, the following program is expected to call the copy constructor. #include <iostream> using namespace std; class A { public: A() { cout << "default" ; } A(int i) { cout << "int" ; } A(const A& a) { cout << "copy"; } }; int main () { A a1; A a2(0); A a3 = 0; return 0; } That is evident if you declare the copy constructor explicit in above case (the compiler errors out). But I don't I see the output of copy constructor when it is not declared as explicit. I guess that is because of copy

Is there a way to disable copy elision in c++ compiler

拈花ヽ惹草 提交于 2020-01-13 17:57:18
问题 In c++98, the following program is expected to call the copy constructor. #include <iostream> using namespace std; class A { public: A() { cout << "default" ; } A(int i) { cout << "int" ; } A(const A& a) { cout << "copy"; } }; int main () { A a1; A a2(0); A a3 = 0; return 0; } That is evident if you declare the copy constructor explicit in above case (the compiler errors out). But I don't I see the output of copy constructor when it is not declared as explicit. I guess that is because of copy

Ignore the Binding initialization

无人久伴 提交于 2020-01-13 10:33:53
问题 The inital problem is coming from a personal project about the polyline of the Xamarin.Forms.Map where the initialization is realized by a binding from the XAML part.. Let me be clear by an example : I have an object CustomMap.cs which inherit from Xamarin.Forms.Map (This file is in the PCL part -> CustomControl/CustomMap.cs) public class CustomMap : Map, INotifyPropertyChanged { public static readonly BindableProperty PolylineAddressPointsProperty = BindableProperty.Create(nameof

Variable initalisation in while loop

纵然是瞬间 提交于 2020-01-13 10:19:09
问题 I have a function that reads a file in chunks. public static DataObject ReadNextFile(){ ...} And dataobject looks like this: public DataObject { public string Category { get; set; } // And other members ... } What I want to do is the following basically List<DataObject> dataObjects = new List<DataObject>(); while(ReadNextFile().Category == "category") { dataObjects.Add(^^^^^ the thingy in the while); } I know it's probably not how it's done, because how do I access the object I've just read.

F# Object Initialization with a Constructor

北城余情 提交于 2020-01-13 08:15:11
问题 I know that in F# if you have a C# class of the format: public class Person { public DateTime BirthDate { get; set; } public string Name { get; set; } } You can initialize it like so, which is nice: let p = new Person (Name = "John", BirthDate = DateTime.Now) However how would you initialize it in F# if the C# class also had a constructor like this: public class Person { public Person(int id) { Id = id } public int Id {get; private set;} public DateTime BirthDate { get; set; } public string

What happens when import modules in python?

点点圈 提交于 2020-01-13 03:07:34
问题 I want to know really what happens when we import a module file in python.I mean it's process, in other words what things by python will be run or check?! like __init__.py or sys.modules and etc. for example i know __init__.py are necessary files in every package,i want to know python what does with these files on import time? please light this for me. 回答1: Read the tutorial section about modules, the documentation of the import statement, the imp module (particularly the examples) and maybe

C++ static variables initialization order

守給你的承諾、 提交于 2020-01-13 02:13:12
问题 1) If I'm not mistaken, C++ standard guarantees that static variables in a single translation unit are initialized in their definition order. And I'm confused about the following code fragment: extern int n; int k = n; int n = 2; extern int n; is the declaration, not the definition, so k is defined before n , but GCC, Clang and MSVC all show me that k == 2 after the initialization of the global variables. For me it's unclear how can k be assigned 2 after int k = n; , because n is not

Why is this nested macro replacement failing?

二次信任 提交于 2020-01-12 14:33:11
问题 I am trying to apply the X Macro concept, in order to have the possibility to initialize all struct members to a custom default (invalid) value. I write the following code: #define LIST_OF_STRUCT_MEMBERS_foo \ X(a) \ X(b) \ X(c) #define X(name) int name; struct foo { LIST_OF_STRUCT_MEMBERS_foo }; #undef X #define X(name) -1, static inline void foo_invalidate(struct foo* in) { *in = (struct foo){ LIST_OF_STRUCT_MEMBERS_foo }; } #undef X #define X(name) -1, #define foo_DEFAULT_VALUE { LIST_OF

Why is this nested macro replacement failing?

徘徊边缘 提交于 2020-01-12 14:32:04
问题 I am trying to apply the X Macro concept, in order to have the possibility to initialize all struct members to a custom default (invalid) value. I write the following code: #define LIST_OF_STRUCT_MEMBERS_foo \ X(a) \ X(b) \ X(c) #define X(name) int name; struct foo { LIST_OF_STRUCT_MEMBERS_foo }; #undef X #define X(name) -1, static inline void foo_invalidate(struct foo* in) { *in = (struct foo){ LIST_OF_STRUCT_MEMBERS_foo }; } #undef X #define X(name) -1, #define foo_DEFAULT_VALUE { LIST_OF

Default initialization in java

徘徊边缘 提交于 2020-01-12 07:21:46
问题 I have a confusion about variable initialization in Java. As I understand, class variables get default initialization while local variables are not initialized by default. However, if I create an array inside a method using the new keyword, it does get initialized by default. Is this true of all objects? Does using the new keyword initialize an object regardless of whether it's a class variable or local variable? 回答1: Is this true of all objects? Does using the new keyword initialize an