Search Results

Search found 30650 results on 1226 pages for 'object initialization'.

Page 48/1226 | < Previous Page | 44 45 46 47 48 49 50 51 52 53 54 55  | Next Page >

  • memset for initialization in C++

    - by skydoor
    memset is sometimes used to initialize data in a constructor like the example below. Does it work in general ? Is it a good idea in general? class A { public: A(); private: int a; float f; char str[35]; long *lp; }; A::A() { memset(this, 0, sizeof(*this)); }

    Read the article

  • Repository, Service or Domain object - where does logic belong?

    - by betitall
    Take this simple, contrived example: UserRepository.GetAllUsers(); UserRepository.GetUserById(); Inevitably, I will have more complex "queries", such as: //returns users where active=true, deleted=false, and confirmed = true GetActiveUsers(); I'm having trouble determining where the responsibility of the repository ends. GetActiveUsers() represents a simple "query". Does it belong in the repository? How about something that involves a bit of logic, such as: //activate the user, set the activationCode to "used", etc. ActivateUser(string activationCode);

    Read the article

  • In java can i have more than one class/object in a file?

    - by David
    So the way i've been told to do things is you have your file and the file name is Classname.java and then the code is something like this: class ClassName { SOME METHODS main {} } and then thats all. I'd like to have two objects defined and used within the same .java file. (i don't want to have to put the other class in a difernt file just because i'd like to send this to someone and i want to avoid hasstle of atatching multiple files to an email [the lazy do make good programers though if you think about it]) is it possible to do this? do i have to do anything special and if so what? what are some mistakes i'm likely to make or that you have made in the past when doing this?

    Read the article

  • Object inside of array -- works in one scope but not in another?

    - by Earlz
    Ok I've been learning some of the more advanced aspects of Javascript and now trying to use this I'm stuck. Here is my code: function Data(){} function init(state){ var item; item=new Data(); item.fieldrid=17; item.description='foo'; state.push(item); }; function findInState(state,fieldrid) { for (var item in state) { alert(item.fieldrid); //prints undefined if (item.fieldrid == fieldrid) { return item; } } return null; } var s=[]; init(s); alert(s[0].fieldrid); //prints 17 (expected) alert(findInState(s,17).fieldrid); //exception here. function returns null. A running example is here at jsbin Why does this not work? I would expect the alert in findInState to yield 17 but instead it yields undefined. What am I doing wrong?

    Read the article

  • Singleton with eager initialization

    - by jesper
    I have class X that takes much time to initialize itself. I want to make that class singleton and force its creation when rails application starts. I've made the singleton: class X @@instance = nil def self.instance if @@instance.nil? @@instance = X.new puts 'CREATING' end return @@instance end private_class_method :new end The problem is that every time I use this class I see 'CREATING' in logs. I've tried to put creation of class in initializers directory but it doesn't work either.

    Read the article

  • Initialization of array on heap

    - by Radek Šimko
    How do i manually initiate values in array on heap? If the array is local variable (in stack), it can be done very elegant and easy way, like this: int myArray[3] = {1,2,3}; Unfortunately, following code int * myArray = new int[3]; myArray = {1,2,3}; outputs an error by compiling error: expected primary-expression before ‘{’ token error: expected `;' before ‘{’ token Do i have to use cycle, or not-so-much-elegant way like this? myArray[0] = 1; myArray[1] = 2; myArray[2] = 3;

    Read the article

  • Array of Structs Initialization....

    - by user69514
    Hi I am working on a program where I have to initialize a deck of cards. I am using a struct to represent a card. However I'm not filling it correctly as I get a bunch of zero's when I display the deck of cards. I believe my mistake is in this line but I'm not sure: struct card temp = {"Clubs", value, false}; The code: void initCards(){ int count = 0; int location = 0; const int hand = 12; //add hearts int value=2; while( count < hand ){ struct card temp = {"Hearts", value, false}; cards[location] = temp; value++; count++; } count = 0; //add diamonts value = 2; while( count < hand ){ struct card temp = {"Diamonds", value, false}; cards[count] = temp; value++; count++; } //add spades count = 0; value = 2; while( count < hand ){ struct card temp = {"Spades", value, false}; cards[count] = temp; value++; count++; } //add clubs count = 0; value = 2; while( count < hand ){ struct card temp = {"Clubs", value, false}; cards[count] = temp; value++; count++; } //print the deck for(int i=0; i<52; i++){ cout << cards[i].type << " " << cards[i].rank << endl; } }

    Read the article

  • How do I insert data into a object relational table with multiple ref in the schema.

    - by Yiling
    I have a table with a schema of Table(number, ref, ref, varchar2, varchar2,...). How would I insert a row of data into this table? When I do: "insert into table values (1, select ref(p), ref(d), '239 F.3d 1343', '35 USC § 283', ... from plaintiff p, defendant d where p.name='name1' and d.name='name2');" I get a "missing expression" error. If I do: "insert into table 1, select ref(p), ref(d), ... from plaintiff p, defendant where p.name=...;" I get a "missing keyword VALUES" error.

    Read the article

  • Java Variable Initialization

    - by Samuel Brainard
    Here's a piece of code I wrote. public class cube { private int length; private int breadth; private int height; private int volume; private int density; private int weight; public cube(int l,int b,int h, int d) { length=l; breadth=b; height=h; density=d; } public void volmeShow(){ volume=length*breadth*height; System.out.println("The Volume of the cube is "+this.volume); So if I implement the above cube class like this, public class cubeApp { public static void main(String[] args){ cube mycube = new cube(5,6,9,2); mycube.volumeShow(); I get an output that tells me Volume is 270. But I get an output that says Volume is 0 if I define the volume variable like this: public class cube { private int length; private int breadth; private int height; private int volume=length*breadth*height; private int density; private int weight; public cube(int l,int b,int h, int d) { length=l; breadth=b; height=h; density=d; } public void volmeShow(){ System.out.println("The Volume of the cube is "+this.volume); Can somebody please explain why this is happening? Thanks, Samuel.

    Read the article

  • How do I loop through a SimpleXML object in PHP

    - by Aditya
    I have a simpleXml object and want to read the data from the object , I am new to PHP and dont quite know how to do this. The object details are as follows. I need to read [description] and [hours]. Thankyou. SimpleXMLElement Object ( [@attributes] = Array ( [type] = array ) [time-entry] = Array ( [0] = SimpleXMLElement Object ( [date] = 2010-01-26 [description] = TCDM1 data management: sort & upload NFP SubProducers list [hours] = 1.0 [id] = 21753865 [person-id] = 350501 [project-id] = 4287373 [todo-item-id] = SimpleXMLElement Object ( [@attributes] = Array ( [type] = integer [nil] = true ) ) ) [1] = SimpleXMLElement Object ( [date] = 2010-01-27 [description] = PDCH1: HTML [hours] = 0.25 [id] = 21782012 [person-id] = 1828493 [project-id] = 4249185 [todo-item-id] = SimpleXMLElement Object ( [@attributes] = Array ( [type] = integer [nil] = true ) ) ). Please help me. I tries a lot of stuff , but not getting the syntax right.

    Read the article

  • Looping through a SimpleXML object

    - by Aditya
    I have a simpleXml object and want to read the data from the object , I am new to PHP and dont quite know how to do this. The object details are as follows. I need to read [description] and [hours]. Thankyou. SimpleXMLElement Object ( [@attributes] = Array ( [type] = array ) [time-entry] = Array ( [0] = SimpleXMLElement Object ( [date] = 2010-01-26 [description] = TCDM1 data management: sort & upload NFP SubProducers list [hours] = 1.0 [id] = 21753865 [person-id] = 350501 [project-id] = 4287373 [todo-item-id] = SimpleXMLElement Object ( [@attributes] = Array ( [type] = integer [nil] = true ) ) ) [1] = SimpleXMLElement Object ( [date] = 2010-01-27 [description] = PDCH1: HTML [hours] = 0.25 [id] = 21782012 [person-id] = 1828493 [project-id] = 4249185 [todo-item-id] = SimpleXMLElement Object ( [@attributes] = Array ( [type] = integer [nil] = true ) ) ). Please help me. I tries a lot of stuff , but not getting the syntax right.

    Read the article

  • C++ Class Construction and Member Initialization

    - by anachoret
    The first print shows the member value to be false, and the other two prints show it as true. Why does the first output differ from the last two? #include #include using namespace std; class MyClass { public: bool value; bool stuff; }; class Container { public: vector my_classes; Container() { MyClass c; cout

    Read the article

  • How to serialize a Linq to Sql object graph without hiding the child's "Parent" member

    - by Richard B
    Without hiding the Child object's reference to the Parent object, has anyone been able to use an XmlSerializer() object to move a Linq to SQL object to an XML document, or is the only appropriate way of handling this to create a custom serialization/deserialization class to handle moving the data to/from the xml document? I don't like the idea of hiding the child object's reference to the parent object is why I'm asking. Thx.

    Read the article

  • Object initialization sequence in Objective-C

    - by Alex
    Hello everyone. The Cocoa framework has a convention to always call self = [super init] in the init method of an inherited class, because [super init] may return a new instance. What will happen if I do this? @interface MyClass : NSObject /* or any other class */ { int ivar_; } @end @implementation MyClass - (id)init { ivar_ = 12345; if ((self = [super init])) { NSLog(@"ivar_'s value is %d", ivar_); } return self; } @end In the case when [super init] returns a new instance, what will I see in the console? ivar_'s value is 0? I can't think of a way to check this myself, because I don't know which class may return a new instance from its init method. Also, can't seem to find explicit clarification for this scenario in the docs. Could anyone help me out? Thanks!

    Read the article

  • C++ Static Array Initialization - Memory Issue

    - by donalmg
    Hi, I have a header file which contains a member variable declaration of a static char array: class ABC { public: static char newArray[4]; // other variables / functions private: void setArray(int i, char * ptr); } In the CPP file, I have the array initialized to NULL: char ABC::newArray[4] = {0}; In the ABC constructor, I need to overwrite this value with a value constructed at runtime, such as the encoding of an integer: ABC::ABC() { int i; //some int value defined at runtime memset(newArray, 0, 4); // not sure if this is necessary setArray(i,newArray); } ... void setArray(int i, char * value) { // encoding i to set value[0] ... value [3] } When I return from this function, and print the modified newArray value, it prints out many more characters than the 4 specified in the array declaration. Any ideas why this is the case. I just want to set the char array to 4 characters and nothing further. Thanks...

    Read the article

  • [PHP] How to unset object's inherited properties ?

    - by vbklv
    I have an Object ( [id] => 1 [parent_id] => 0 [result:Database:private] => [db:Database:private] => mysqli Object ( [affected_rows] => 0 ... ) ) Obviously, the Object has inherited the 'db' and 'result' properties of the parent Database class. unset($object-result) nor unset($object-result:Database) nor unset($object-result:Database:private) work. How could I unset those properties when they are no longer needed (i.e. when the object properties are about to be output)? Is it a generally a good idea to have a database object as an inherited property of other classes (extend one Database class with all other classes that use database connections)?

    Read the article

  • Copy not null and not empty fields from one object to another object of the same type(Objects are same type) in java

    - by Chinni
    I am using hibernate, struts, extjs in my project. I have a Customer object with these fields: custId, custName, address, phone and in my project from UI side I get an object customer with custName. So I need to update the above object(custName is unique). I have only one object with the same customer name. So I will get that object using customer name (object from DB). Now I have to save the object with the updated customer name. If I save as follows I have Customer Object from UI, is cust Customer cust1 = getCustomerByName(cust.getCustName()); cust.setCustId(cust1.getCustId()); save(cust); If I do this I lose the customer address and phone number. So, how can I copy one object not null or not empty field values to another object of same type. Can any one please help. I just stuck here. It's stopping me to save. Thanks in advance!

    Read the article

  • C++: Initialization Order for Member Classes

    - by Nikhil
    In the following code, when the ctor of X is called will the ctor of A or B be called first? Does the order in which they are placed in the body of the class control this? If somebody can provide a snippet of text from the C++ standard that talks about this issue, that would be perfect. class A; class B; class X { private: A a; B b; }

    Read the article

  • Force Page initialization

    - by Tony
    Hi The following code is not causing Page_Load of PhotoList to be called. I want the control to be initialized as if it is in normal Page live cycle, what I should do. Page pageHolder = new Page(); UserControl viewControl = (UserControl)pageHolder.LoadControl("Common/PhotoList.ascx"); pageHolder.Controls.Add(viewControl);

    Read the article

< Previous Page | 44 45 46 47 48 49 50 51 52 53 54 55  | Next Page >