constructor

inheritance Problems with undefined types

。_饼干妹妹 提交于 2019-12-13 05:07:22
问题 I want to be able to create a constructor that can call on its types but without any constraints. public class Box { public class Command { public string name; public string num; public Object PARAMS { get; set; }//<--- HERE } } I want PARAMS to be an undefined type that could possibly call one of these other classes public class Person:Box { public string LastName { get; set; } public string FirstName { get; set; } } or public class Item:Box { public string ItemName { get; set; } public

C++ constructor without parameter name [duplicate]

自闭症网瘾萝莉.ら 提交于 2019-12-13 04:57:55
问题 This question already has answers here : Default constructor with empty brackets (9 answers) Closed 5 years ago . I am confused over the behavior of constructor in this code. class htc { public: htc() { std::cout << "HTC_FOO_CONSTRUCTOR" << std::endl ;} htc(const htc&) { std::cout << "HTC_BAR_CONSTRUCTOR" << std::endl;}; }; int main() { htc one; // This outputs HTC_FOO_CONSTRUCTOR htc two(); // This outputs nothing htc three(one) } Couple of questions whats the meaning of using brackets in

Multiple inside-of-class typedef of shared_ptr

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-13 04:46:13
问题 I can currently initialize the following class MyTest template<class T> class MyTest { public: typedef std::shared_ptr<MyTest> Ptr; MyTest( Ptr _nextTest = NULL ) : m_nextTest( _nextTest ) { } ~MyTest() { } private: Ptr m_nextTest; }; like so MyTest<int>::Ptr my( new MyTest<int>() ); What I would now also like to be capable of is having a MyTest of a different type as an argument for the constructor as in MyTest<int>::Ptr my( new MyTest<float>() ); But this obviously brakes (*1) as my typedef

How to create a nonempty boost ublas::vector inside an initializer list?

馋奶兔 提交于 2019-12-13 04:44:59
问题 I'm trying to do something like this #include <boost/numeric/ublas/vector.hpp> using namespace boost::numeric::ublas; class A{ protected: vector< double > a_; public: A( vector< double > a ) : a_( a ) {}; }; class B : public A{ public: B() : A( vector< double >( { 1.25, 2.75, 3.34 } ) ){}; }; The result should be, that the vector a_ gets declared as a three-vector containing a_[0]=1.25, a_[1]=2.75, a_[2]=3.34 . This code is not working because boost::numeric::ublas::vector does not have a

How to hide functions within classes in c#?

时光怂恿深爱的人放手 提交于 2019-12-13 04:39:29
问题 I need to hide few methods inside a class based on the parameter that is passed to the constructor in c#. How would I do this? Thanks in advance! More Info: I was part of this GUI development where they had a API with access to registers in a hardware. Now they are releasing a newer hardware so I need to support both old and new one which has a newer API(Mostly duplicate of old one with some old removed and some new registers added). Moreover, I need to keep this only one class called "API"

Best way to create a new constructor that relies on an old one using prototypes

你。 提交于 2019-12-13 04:38:38
问题 So, suppose I have the following constructor function, whose prototype I have modified like so: function foo(options) { this.propA_ = 'whatever'; this.propB_ = 'something'; this.propC_ = options.stuff; this.randomMethod = function omg() { /*code etc etc etc*/ } } foo.prototype.p1 = 1; foo.prototype.p2 = 2; After I have made foo, I want to create a new constructor, bar(), that is like a sort super foo: it has all of the properties, prototpye info, and methods of foo, but it ALSO has some extra

Object initialization in RubyMotion

本秂侑毒 提交于 2019-12-13 04:25:42
问题 I am new to RubyMotion and trying to understand how object initialization works. Suppose a simple class with one class and one instance method: class Something def self.getSomething BubbleWrap::HTTP.post("http://example.com") do |response| p response end end def getSomething BubbleWrap::HTTP.post("http://example.com") do |response| p response end end end Now, why does the following work: Something.getSomething And the next snippet not, well, sometimes (ran this snippet and the runtime crashed

Parsing array in library constructor - Pointer problem (C++)

大憨熊 提交于 2019-12-13 04:12:58
问题 I am trying to develop an Arduino library that consists out of two classes. I want 'WayPointStack' to store an array of 'WPCommand', but I can't get it to work. It is obviously a pointer problem, but I don't know how to solve it. There are four errors left in my code: WayPointStack.cpp:23:7: error: incompatible types in assignment of 'WPCommand*' to 'WPCommand [0]' _wp = new WPCommand[arrSize]; //Fixed WayPointStack.cpp:44:34: error: could not convert '(operator new(16u), (((WPCommand*)

Codeigniter Login check issue in construct / infinite loop

你说的曾经没有我的故事 提交于 2019-12-13 04:08:07
问题 i need to check is user loged or not. i have to many function in controller, so i check it in construct function. but its entering infinite loop. problem is: infinite loop. function __construct() { parent:: __construct(); $this->is_logged_in(); $this->clear_cache(); } function is_logged_in() { if( !class_exists('CI_Session') ) $this->load->library('session'); if( $this->session->userdata('login') ) { $data['name'] = $this->session->userdata('username'); } else { redirect(base_url('admin/login

Can't set cookie inside construct in codeigniter

谁说胖子不能爱 提交于 2019-12-13 04:05:55
问题 I trying to set a cookie if null but I can't get it to work: public function __construct() { parent::__construct(); if ($this->input->cookie('ff', TRUE) == FALSE) { $this->input->set_cookie('ff', 'on', 86500); dump($this->input->cookie('ff', TRUE)); } } What am I doing wrong? Edit: dump() it's just a custom debug function. 回答1: A couple of reasons your set_cookie call might fail: 1) You've output something to the browser already when set_cookie is called, in which case you might get an error