Here goes a command object which needs to be populated from a Spring form
public class Person {
private String name;
private Integer age;
/**
* on-demand initialized
*/
private Address address;
// getter's and setter's
}
And Address
public class Address {
private String street;
// get...
I am trying to statically initialize the following structure in Visual Studio 2010:
struct Data
{
int x;
union
{
const Data* data;
struct {int x; int y; };
};
};
The following is fails with error C2440: 'initializing' : cannot convert from 'Data *' to 'char'.
static Data d1;
static Data d = {1, &d1};
static Da...
I want to know, in c++, when does the initialization of objects take place?
Is it at the compile time or link time?
For ex:
//file1.cpp
extern int i;
int j=5;
//file2.cpp ( link with file1.cpp)
extern j;
int i=10;
Now, what does compiler do : according to me, it allocates storage for variables.
Now I want to know :
does it also p...
I was reading about SIOF from a book and it gave an example :
//file1.cpp
extern int y;
int x=y+1;
//file2.cpp
extern int x;
int y=x+1;
Now My question is :
In above code..will following things happen ?
1. while compiling file1.cpp, compiler leaves y as it is i.e doesn't allocate storage for it.
2. compiler allocates storage for ...
I am getting very confused in some concepts in c++. For ex: I have following two files
//file1.cpp
class test
{
static int s;
public:
test(){s++;}
};
static test t;
int test::s=5;
//file2.cpp
#include<iostream>
using namespace std;
class test
{
static int s;
public:
test(){s++;}
static int get()
{
...
This is the way I get to prevent funA,funB,funC, etc.. for being used before init
#define INIT_KEY 0xC0DE //any number except 0, is ok
static int initialized=0;
int Init()
{
//many init task
initialized=INIT_KEY;
}
int funA()
{
if (initialized!=INIT_KEY) return 1;
//..
}
int funB()
{
if (initialized!=INIT_KEY) return 1;
//....
Hi,
Which of these two forms of Array Initialization is better in Ruby?
Method 1:
DAYS_IN_A_WEEK = (0..6).to_a
HOURS_IN_A_DAY = (0..23).to_a
@data = Array.new(DAYS_IN_A_WEEK.size).map!{ Array.new(HOURS_IN_A_DAY.size) }
DAYS_IN_A_WEEK.each do |day|
HOURS_IN_A_DAY.each do |hour|
@data[day][hour] = 'something'
end
end
Method ...
Hi folks,
I'm having a problem with enum type initialization that appears to be simple to solve but I haven't figured out how to do it.
Suppose I declare the following enum type:
typedef enum NXSoundType {
NXSoundTypeNone,
NXSoundTypeEffect,
NXSoundTypeBackgroundMusic
} NXSoundType;
I declare a convenience method for retu...
Quick beginner's question:
Do I have to initialize simple class member variables, or are they guaranteed to get assigned their default values in any case?
Example:
class Foo {
int i;
// is i==0 or do I need the following line for that?
Foo() : i(0) {}
};
Thanks!
...
Do you guys have your own little framework for project startups ? I mean, every time one needs to do the same things at the beginning:
Context initialization - ideally after arguments are processed. Sometimes without interactive user input, sometimes with input reader. Sometimes we need to load properties, sometimes not. Then we need ...
Clients have many Invoices. Invoices have a number attribute that I want to initialize by incrementing the client's previous invoice number.
For example:
@client = Client.find(1)
@client.last_invoice_number
> 14
@invoice = @client.invoices.build
@invoice.number
> 15
I want to get this functionality into my Invoice model, but I'm not ...
Was just doing a code review and started to wonder:
I thought if (self = [super init]) checks whether assigning return value of [super init] to variable self was successful or not (value of operation). Thus (self = nil) would actually be TRUE.
I thought if ((self = [super init])) checks what is the value of self after assignment (value...
We have a data provider class that returns repositories for each aggregate in our database.
Let's consider following scenario:
public class DataProvider {
public IBookRepository Books { get { retun new BookRepository(); } }
public IAuthorRepository Authors { get { retun new AuthorRepository(); } }
}
As you can see, we return ...
I'm often running into the same trail of thought when I'm creating private methods, which application is to modify (usually initialize) an existing variable in scope of the class.
I can't decide which of the following two methods I prefer.
Lets say we have a class Test with a field variable x. Let it be an integer. How do you usually m...
Is there an mechanism or trick to run a function when a program loads?
What I'm trying to achieve...
void foo(void)
{
}
register_function(foo);
but obviously register_function won't run.
so a trick in C++ is to use initialization to make a function run
something like
int throwaway = register_function(foo);
but that doesn't wo...
Hi,
I am a Python newbie coming from a C++ background. While I know it's not Pythonic to try to find a matching concept using my old C++ knowledge, I think this question is still a general question to ask:
Under C++, there is a well known problem called global/static variable initialization order fiasco, due to C++'s inability to decid...
I have two simple related controls on a form, a delete button and a confirm delete checkbox.
The idea is to protect against accidental deletions (don't worry, undo will be added later) but still allow the user to delete without annoying confirmations if they so wish.
However, I want the initial state of the checkbox to be set. The XAML...
Coming from a C background, I've always assumed the POD types (eg ints) were never automatically zero-initialized in C++, but it seems this was plain wrong!
My understanding is that only 'naked' non-static POD values don't get zero-filled, as shown in the code snippet. Have I got it right, and are there any other important cases that I'...
Is it "better" to initialize AS3 class variables in the class constructor? Or can I just initialize them to their default value when I declare them at the top of my class? I ask because when there's a lot of class variables, it appears inefficient to declare them in one place and then initialize them in another when I could easily do b...
I need a dinamically allocated bi-dimensional array of objects.
I declared a static pointer to pointer to object as follows:
server_session **server_session::Pglvcl_sess;
There's a method to populate dinamically the array of array of object:
int server_session::createSession()
{
int ret = -1;
// looks for the next available posi...