default-constructor

Naming user controls without default constructors in XAML

霸气de小男生 提交于 2019-12-22 05:39:13
问题 I have a user control without a parameterless constructor; let's call it WithoutDefaultConstructor . I want to insert a WithoutDefaultConstructor called myControl into the XAML code of another control (which is called MainWindow ). However, I get this compiler error: The type 'WithoutDefaultConstructor' cannot have a Name attribute. Value types and types without a default constructor can be used as items within a ResourceDictionary. How do I fix this without adding a parameterless constructor

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

Is it guaranteed that defaulted constructor initialize built in types automatically to 0?

╄→гoц情女王★ 提交于 2019-12-22 03:42:20
问题 Before you start to mark this as duplicate I've already read this .But It doesn't answer my question. The linked question talks about C++98 & C++03 but my question is about defaulted constructor introduced by C++11. Consider following program (See live demo here): #include <iostream> struct Test { int s; float m; Test(int a,float b) : s(a),m(b) { } Test()=default; }t; int main() { std::cout<<t.s<<'\n'; std::cout<<t.m<<'\n'; } My question is that is the defaulted constructor provided by

Are empty constructors always called in C++?

末鹿安然 提交于 2019-12-21 12:17:46
问题 I have a general question, that may be a little compiler-specific. I'm interested in the conditions under which a constructor will be called. Specifically, in release mode/builds optimised for speed , will a compiler-generated or empty constructor always be called when you instantiate an object? class NoConstructor { int member; }; class EmptyConstructor { int member; }; class InitConstructor { InitConstructor() : member(3) {} int member; }; int main(int argc, _TCHAR* argv[]) { NoConstructor*

In which cases there is no constructor at all, even a default constructor?

爱⌒轻易说出口 提交于 2019-12-21 11:22:20
问题 In this book I am currently reading I ran across this: A class doesn't need a constructor. A default constructor is not needed if the object doesn't need initialization. Am I correct in inferring from the above that the compiler does not generate a default constructor for the class/structure in some cases? If yes, what are those cases? I will venture and say POD is probably one. Are there any other? EDIT: I have changed the title as the original title gave the meaning that I asked when was a

Will default-constructing an integer array zero-initialize it?

混江龙づ霸主 提交于 2019-12-21 11:01:23
问题 If I have a structure with an array member, and I explicitly call the default constructor of the array in the structure's constructor, will the elements get default-constructed? (In the case of an integer array, this would mean getting zero-initialized). struct S { S() : array() {} int array[SIZE]; }; ... S s; // is s.array zero-initialized? A quick test with gcc suggests that this is the case, but I wanted to confirm that I can rely on this behaviour. (I have noticed that if I don't

Default constructor/destructor outside the class?

自古美人都是妖i 提交于 2019-12-21 03:37:34
问题 Is the following legal according to the C++11 standard ( = default outside the definition of the class) ? // In header file class Test { public: Test(); ~Test(); }; // In cpp file Test::Test() = default; Test::~Test() = default; 回答1: Yes, a special member function can be default-defined out-of-line in a .cpp file. Realize that by doing so, some of the properties of an inline-defaulted function will not apply to your class. For example, if your copy constructor is default-defined out-of-line,

Unintuitive behaviour with struct initialization and default arguments

柔情痞子 提交于 2019-12-21 03:22:08
问题 public struct Test { public double Val; public Test(double val = double.NaN) { Val = val; } public bool IsValid { get { return !double.IsNaN(Val); } } } Test myTest = new Test(); bool valid = myTest.IsValid; The above gives valid==true because the constructor with default arg is NOT called and the object is created with the standard default val = 0.0. If the struct is a class the behaviour is valid==false which is what I would expect. I find this difference in behaviour and particularly the

Why PHP has no default constructor? [closed]

安稳与你 提交于 2019-12-20 19:38:37
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 8 years ago . Why can't I use code like this? <?php class NoConstructor { } class ChildWithConstructor extends NoConstructor { public function _

C# - Calling a struct constructor that has all defaulted parameters

假装没事ソ 提交于 2019-12-20 17:35:54
问题 I ran into this issue today when creating a struct to hold a bunch of data. Here is an example: public struct ExampleStruct { public int Value { get; private set; } public ExampleStruct(int value = 1) : this() { Value = value; } } Looks fine and dandy. The problem is when I try to use this constructor without specifying a value and desiring to use the defaulted value of 1 for the parameter: private static void Main(string[] args) { ExampleStruct example1 = new ExampleStruct(); Console