default-constructor

In MATLAB, is it possible to check if an object already exists before creating a new one?

拈花ヽ惹草 提交于 2019-12-13 18:16:05
问题 I'm trying to figure out how to ask the user whether they want to replace the previous object of the same class with the default object, or simply use the previous object, when calling the constructor. I'm looking for actions in both these cases: >>obj = Obj() 'obj' already exists. Replace it with default? (y/n): y %clear obj and call default constructor to create new obj >>obj = Obj() 'obj' already exists. Replace it with default? (y/n): n %cancel call of Obj() How would I do this? I've

In Akka Java actor model, can a router create actors with non-default constructor?

不羁岁月 提交于 2019-12-12 18:16:10
问题 In Akka Java actor model, if I have a RoundRobinRouter, when its tell() method is called, I want the router (as the master) to create children actors with non-default constructor because I need to pass in some parameters. How can I do this? I understand that I can an actor with non-default constructor using Props , but how is it used when the master actor is a router? Thanks! 回答1: The props in the construction of a Router is the props for the routees of that router, not the router itself. You

use parameterized constructor in other classes constructor

爱⌒轻易说出口 提交于 2019-12-12 14:07:35
问题 I fear that this is a very basic question, however, I was not able to solve it yet. I have a class A // classA.h ... class ClassA { public: ClassA(); ClassA(int foo); private: int _foo; ... } // classA.cpp ClassA::ClassA() { _foo = 0; } ClassA::ClassA(int foo) { _foo = foo; } ... A second class B uses an instance of class A in the constructor: // classB.h ... #include "classA.h" #define bar 5 class ClassB { public: ClassB(); private: ClassA _objectA; ... } // classB.cpp ClassB::ClassB() {

How to use stringstream constructor in getline?

删除回忆录丶 提交于 2019-12-12 12:42:04
问题 Following up https://stackoverflow.com/a/1120224/390066. Why can't I use getline(stringstream(line),cell,','){} instead of stringstream lineStream(line); getline(lineStream,cell,','){} ? update I should have clarified that I want to use getline within a loop. Furthermore, I should have also noted that my initial intention was to read a file line-by-line using getline and use the line from that in the new getline that would divide on ',', which is more intuitive imo. From what I understood so

c++ is default constructor called in parametrized constructor?

寵の児 提交于 2019-12-12 05:14:02
问题 I have the following template class: template<typename T, int nSize> class Stack{ private: int m_nCurrentPos; Array<T> m_tArray; public: Stack(int nCurrentPos = 0); ... }; I would like the default constructor work as follows: template<typename T, int nSize> Stack<T,nSize>::Stack(int nCurrent){ m_nCurrent = nCurrentPos; m_tArray = Array<T>::Array(nSize); }; Where Array looks like that: template <typename T> class Array{ private: T* m_cData; int m_nSize; static int s_nDefaultSize; public: Array

Why does constructor with arg undefine the default constructor?

痞子三分冷 提交于 2019-12-12 03:46:49
问题 Consider - public class Class_A { public void func() {...} public void func(int a){...} All three - Class_A a = new Class_A(); // legal a.func(); // legal a.func(1); // legal But After constructor with arg like public Class_A (int a){...} is added to Class_A , the default constructor become to be - Class_A a = new Class_A(); // The constructor Class_A() is undefined Thats force me to add public Class_A() {/*Do Nothing*/} into Class_A . Since each class has default constructor , why doesn't

c++, boost, store objects in multidimensional array without default constructor

不羁岁月 提交于 2019-12-12 01:13:41
问题 I want to store thousands of interpolation functions in a multidimensional array, preferable the one from boost. The main problem is that the interpolation function I use is a class that does not have a default constructor. This prohibits me to initialize the multidimensional array. What I wish I could do: double func(const double& x1, const double& x2, const double& x3) { return x1 + x2 + x3; }; int main() { std::vector<double> x1 {0, 1, 2, 3}; std::vector<double> x2 {1.1, 1.2, 1.3, 1.4, 1.5

Kotlin default constructor

两盒软妹~` 提交于 2019-12-11 18:28:32
问题 The docs say: On the JVM, if all of the parameters of the primary constructor have default values, the compiler will generate an additional parameterless constructor which will use the default values. This makes it easier to use Kotlin with libraries such as Jackson or JPA that create class instances through parameterless constructors. But this does not appear to be the case: Welcome to Kotlin version 1.2.71 (JRE 10.0.2+13-Ubuntu-1ubuntu0.18.04.2) Type :help for help, :quit for quit >>> class

Overloaded parent class constructors. Wrong inizializer choice?

别来无恙 提交于 2019-12-11 14:56:46
问题 I would like to add a Child class to a pre-existing project having Parent already defined and declared. Parent class has got two constructors with initializer-list. This is my code, and it generates error C2668: 'Parent::Parent' : ambiguous call to overloaded function. Where is my error? Thanks @Mape for your snippet #include <stdio.h> class Parent { public: // Here a constructor with one default trailing argument, i.e. myInt, // myDouble is not initialised. This is correct, as once one

No appropriate default constructor available in struct with glm vectors

為{幸葍}努か 提交于 2019-12-11 10:29:31
问题 in .h: enum collisionType {AB, BA, AoverB, AunderB}; struct Collision { public: collisionType type; glm::vec2 point1; glm::vec2 point2; Collision(enum collisionType, glm::vec2, glm::vec2); }; in .cpp: Collision::Collision(enum collisionType collisType, glm::vec2 p1, glm::vec2 p2) : type(collisType), point1(p1), point2(p2) { } using it std::vector<Collision> collisions; glm::vec2 point1(11.0, 12.0); glm::vec2 point2(12.0, 13.0); collisions.push_back(Collision(AoverB, point1, point2)); Getting