instance

Difference between Object and instance : C++

落花浮王杯 提交于 2019-12-18 16:57:35
问题 I followed a number of posts on SO, and finally I can draw a conclusion that when we have something like : Person name; name is an object of class person . It becomes instance when instantiate it : name=new Person(); I am a beginner in C++, and so far I have seen we can access the functions and variables like: Person name; name.getValue; name.callFunction(); We need not to use new operator for this. So can we say the differentiating factor between an object and instance can be ignored in C++?

Mongoose instance method is undefined

假如想象 提交于 2019-12-18 16:10:09
问题 I defined an instance method with Mongoose to authenticate a rep (user): RepSchema.methods.authenticate = function(password){ return this.encryptPassword(password) === this.hashed_password; }; In my app, I find the rep and call the authenticate method on it: var mongoose = require("mongoose"); var Rep = mongoose.model("Rep"); Rep.findOne({email: email}, function(err, rep){ if (rep.authenticate(req.body.session.password)){ req.session.rep_id = rep._id; res.redirect('/calls', {}); } }); However

Dynamically creating an instance of a class from a string containing the class name in C++

拈花ヽ惹草 提交于 2019-12-18 13:07:30
问题 Lets say I have a base class with 100 children: class Base { virtual void feed(); ... }; class Child1 : public Base { void feed(); //specific procedure for feeding Child1 ... }; ... class Child100 : public Base { void feed(); //specific procedure for feeding Child100 ... }; At runtime I want to read a file that contains which children to create and feed. Lets say I've read the file and the vector of strings "names" contains the names of the child classes (ie. Child1, Child4, Child99). Now I'm

Bootstrap with CKEditor equals problems

六眼飞鱼酱① 提交于 2019-12-18 12:27:42
问题 I'm trying to create a Bootstrap modal which contains an instance of CKEditor, but there are a lot of problems... So basically the fields are left unenabled, they don't look like, but I can't interact with them. Does anybody have a solution to this strange behavior? 回答1: FWIW, I couldn't get Peter's solution to work, but the following worked for me, and still keeps the hack in a separate file so you don't have to edit any Bootstrap source files: // bootstrap-ckeditor-modal-fix.js // hack to

Create an anonymous class instance in python

大兔子大兔子 提交于 2019-12-18 11:44:53
问题 Sometimes i need to create an anonymous class instance in python, just like c#: var o= new {attr1="somehing", attr2=344}; but in python i do it in this way: class Dummy: pass o = Dummy() o.attr1 = 'something' o.attr2 = 344 #EDIT 1 print o.attr1, o.attr2 how can do that in pythonic way in single statement? 回答1: o = type('Dummy', (object,), { "attr1": "somehing", "attr2": 344 }) o.attr3 = "test" print o.attr1, o.attr2, o.attr3 回答2: type while this is not precisely a single statement I think

Java: super.clone() method and inheritance

走远了吗. 提交于 2019-12-18 11:28:23
问题 I have a quick question regarding the clone() method in Java, used as super.clone() in regard to inheritance - where I call the clone() method in the parent class all the way up from the button. The clone() method is supposed to return a copy of this object, however if I have three classes in an inheritance heirachy and call super.clone() three times, why doesn't the highest class in the inheritance heirachy, just under class Object, get a copy of that class returned? Suppose we have three

best way to create object

末鹿安然 提交于 2019-12-18 11:03:18
问题 This seems to be very stupid and rudimentary question, but i tried to google it, but couldn't a find a satisfactory answer, public class Person { public string Name { get; set; } public int Age { get; set; } public Person(){} public Person(string name, int age) { Name = name; Age = age; } //Other properties, methods, events... } My question is if i have class like this, what is the best way to create an object? Person p=new Person("abc",15) OR Person p=new Person(); p.Name="abc"; p.Age=15;

SQLAlchemy: Modification of detached object

余生颓废 提交于 2019-12-18 10:35:57
问题 I want to duplicate a model instance (row) in SQLAlchemy using the orm. My first thought was to do this: i = session.query(Model) session.expunge(i) old_id = i.id i.id = None session.add(i) session.flush() print i.id #New ID However, apparently the detached object still "remembers" what id it had, even though I set the id to None while it was detached. Thus, session.flush() tries to execute an UPDATE changing the primary key to null. Is this expected behavior? How can I remove the 'memory' of

Appending el in Backbone from an instance

白昼怎懂夜的黑 提交于 2019-12-18 09:38:46
问题 I'm attempting to append the html within el from instances var Article1 = Backbone.View.extend({ initialize: function(options) { console.log('type 1', options) this.flyIn(options); }, flyIn: function(options) { this.$el.find('.superDog').css({ display: 'block' }); this.$el.find('.superDog').animate({ top: options.top, left: options.left }, 3000); }, render: function() { }, el: '<div><p class="superDog"></p></div>' }); var Article1A = new Article1({ color: 'black', top: '300', left: '300',

How to “invoke” a class instance in PHP?

不想你离开。 提交于 2019-12-18 05:51:20
问题 is there any possibility to "invoke" a class instance by a string representation? In this case i would expect code to look like this: class MyClass { public $attribute; } $obj = getInstanceOf( "MyClass"); //$obj is now an instance of MyClass $obj->attribute = "Hello World"; I think this must be possible, as PHP's SoapClient accepts a list of classMappings which is used to map a WSDL element to a PHP Class. But how is the SoapClient "invoking" the class instances? 回答1: $class = 'MyClass';