constructor

Overridable Methods In Constructors -Help to Fix

半城伤御伤魂 提交于 2019-12-11 09:03:37
问题 Im attempting to use fxCop on a C# Project as kind of basis for C# coding standards. The project Im using is called S#arp Architecture and is freely available here: S#Arp Arch Now if I run fxCop (most things have been fixed already) I need to fix the CA2214 fxcop error for overridable methods in contructors. At the moment a piece of violating code looks like this: public class Region : Entity, IHasAssignedId<int> { public Region(string description) { Check.Require(!string.IsNullOrEmpty

Python class setup for serialization without pickle

大憨熊 提交于 2019-12-11 07:56:49
问题 Scenario I am looking for an object oriented approach in python that makes it possible to save an instance of a class in a data file and also load it again in at a later point in time. My current approach looks like this: class A(object): def __init__(self, ComplexParam1, ComplexParam2): self.ComplexParam1 = ComplexParam1 self.ComplexParam2 = ComplexParam2 @staticmethod def Create(EasyParam1, EasyParam2): #do some complex calculation to get ComplexParam1 and ComplexParam2 from EasyParam1 and

how does the compiler choose automatic type conversion method

若如初见. 提交于 2019-12-11 07:53:25
问题 In this code, two methods were used to allow conversion of Y object into X object. compiling by g++ always choose constructor. if constructor is private like : private : Y(const X&){std::cout << "Y constructor...\n" ; } conversion is prevented either by operator or constructor. if constructor is private and explicit private : explicit Y(const X&){std::cout << "Y constructor...\n" ; } compiler use operator instead. Is it the usual way to prevent auto conversion by making conversion constructor

How to define a static constexpr matrix in c++14?

牧云@^-^@ 提交于 2019-12-11 07:48:53
问题 I am currently using C++14. I would like to define a Matrix class which I can use for defining runtime matrices, but also constexpr matrices. I also would like to define static constexpr matrices based on such a class. I consider this as a starting point for the Matrix class. Then I would like to write something as: static constexpr Matrix<double,2,2> staticmat{0.1,0.2,0.3,0.4}; so that staticmat is constexpr and unique, being static. However, in order to initialise this, I would need a

C++ Classes default constructor

倖福魔咒の 提交于 2019-12-11 07:45:33
问题 Earlier I asked why this is considered bad: class Example { public: Example(void); ~Example(void); void f() {} } int main(void) { Example ex(); // <<<<<< what is it called to call it like this? return(0); } Now, I understand that it's creating a function prototype instead that returns a type Example. I still don't get why it would work in g++ and MS VC++ though. My next question is using the above, would this call be valid? int main(void) { Example *e = new Example(); return(0); } ? What is

Using a global array inside a class

落花浮王杯 提交于 2019-12-11 07:44:02
问题 My aim is to retrieve some data from a global array which is defined in another PHP file. My code is running inside "database.php" file and the array I want to use is inside "config.php" file. My code is as below: config.php $CONFIG = array(); // ... $CONFIG["DATABASE"] = array(); $CONFIG["DATABASE"]["USERNAME"] = "user"; $CONFIG["DATABASE"]["PASSWORD"] = "pass"; $CONFIG["DATABASE"]["HOSTNAME"] = "127.0.0.1"; $CONFIG["DATABASE"]["DATABASE"] = "my_db"; // ... database.php require('config.php')

Rest exception: Unable to find a constructor to use for type “myclass”. A class should either have a default constructor

血红的双手。 提交于 2019-12-11 07:37:32
问题 I know this question has been asked before, but I can't find an answer to solve this problem. I'm making a request to a web service which returns a json, and then I save that json as an object in a list using json.net. List<myclass> result; var request = new RestRequest(url, Method.POST); //Set the parameters of the request //[...] IRestResponse response = client.Execute(request) Console.WriteLine(response.Content); //response.Content = [{"nomPrecio":"string","nomPrecioEN":"string",

Cannot use constructor for public class within same namespace due to protection level?

扶醉桌前 提交于 2019-12-11 07:29:20
问题 I am currently trying to map alot of channel, and have thus for convenient sake, made a class that can contain the channel properties and a dictionary, that maps an ID to a channel. The dictioanary is on one class and the channel definition is in their own classes but, within the same namespace. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using ParentId = System.String; using ChildIds = System.Collections.Generic.List<int

Curly braces constructor prefers initializer_list over better match. Why?

 ̄綄美尐妖づ 提交于 2019-12-11 07:28:20
问题 #include <vector> using std::size_t; struct Foo { Foo(size_t i, char c) {} }; Foo Bar1() { size_t i = 0; char c = 'x'; return { i, c }; // good } std::vector<char> Bar2() { size_t i = 0; char c = 'x'; return { i, c }; // bad } https://wandbox.org/permlink/87uD1ikpMkThPTaw warning: narrowing conversion of 'i' from 'std::size_t {aka long unsigned int}' to 'char' inside { } Obviously it tries to use the initializer_list of vector. But why doesn't it use the better match vector<char>(size_t, char

C++ singleton with private constructor

徘徊边缘 提交于 2019-12-11 07:23:53
问题 I need singleton with a application lifetime, guaranteed creation/destruction and static access to it. #include <iostream> #include <cstdlib> #define DISALLOW_COPY_AND_ASSIGN(TypeName) \ TypeName(const TypeName&); \ void operator=(const TypeName&) #define M() C::sM() #define M2() C::sM2() using namespace std; class C { private: static C* s; ~C() { cout << "~C()" << endl; } static C* instance() { if (s==NULL) { s=new C(); } cout << "instance()=" << s << endl; return s; } static void cleanUp()