Suppose we have a map that is shared between multiple threads. It represents a node in some hierarchical structure (say, a directory in a file system) that is stored on disk. Constructing a Value is expensive both in time and in memory. This is the classic 'initialize on demand' problem, with a twist: we're initializing values in a map w...
For example:
int main()
{
{
// I want this array to be part of the inner scope
string s[] = {"Ben","Joe","Bob","Matt"};
// And I want to use it to initialize this vector, but I want this
// vector to be visible in the outer scope
vector<string> names(s,s+4);
}
}
Is there any way to do t...
I have some code to initialize a struct in C#:
namespace Practice
{
public struct Point
{
public int _x;
public int _y;
public int X
{
get { return _x; }
set { _x = value; }
}
public int Y
{
get { return _y; }
set { _y = val...
How should I write an init method for a class which is sub-classing an NSObject
Let's say i have a class named :
CustomButton subclassing UIButton
I have an empty nib file named
CustomButton.nib which has a single
UIButton in it.
IN interface builder the classname for the button is set to "CustomButton"
How would you write an init me...
I am completely new to Perl. I needed to use an external module HTTP::BrowserDetect. I was testing some code and tried to get the name of the OS from os_string method. So, I simply initialized the object and created a variable to store the value returned.
my $ua = HTTP::BrowserDetect->new($user_agent);
my $os_name = $ua->os_string();
...
When writing a function I always have this confusion whether to check for errors first and declare the variables later (or) assign the parameters to local variables and then check for errors. Which of the following way is preferred and why? I usually stick to the first type.
void DoSomething1(Object x, Object y){
// All sort of error...
Hello,
I've a question about initialization of inherited members in constructor of derived class. Example code:
class A
{
public:
int m_int;
};
class B: public A
{
public:
B():m_int(0){}
};
This code gives me the following output:
In constructor 'B::B()':
Line 10: error: class 'B' does not have any field na...
Hey guys, im a bit lost on how to do this. I know how to initialize an array with values at the time of declaration, but how would i do it with a DateTime type array since it takes multiple arguments to create a date??
...
How should I define a Moose object subroutine after its initialization?
I'm writing an object module using Moose and I plan to serialize (nstore) the created objects.
Examine the following (simplified!) example:
package MyObj 0.001;
use Moose;
use namespace::autoclean;
has 'size' => (
is => 'ro',
isa => 'Int',
required...
It is possible to pass uninitialized object to a parent class like in the following example
class C
{
public:
C(int i):
m_i(i)
{};
int m_i;
}
class T
{
public:
T(C & c):
m_c(c)
{
};
C & m_c;
};
class ST : public T
{
public:
ST():
...
I have heard that when you have a subclass, you are supposed to initialize the superclass with the same init function from within the subclass's init. What I mean is that the subclass's init should call [super init] and the subclass's initWithFrame should call [super initWithFrame]. Why is this? Why does calling the super's init from ...
Hi everyone.
I'd like to create a class that is associated to another class in some sort of parent-child relationship. For this the "child" class needs a reference to it's parent.
For example:
template <typename T>
class TEvent {
private: T* Owner;
public: TEvent(T* parent) : Owner(parent) {}
};
class Foo {
private: TEven...
This is something that I've been questioning for some time. How would I create a variable at runtime as named by the value of another variable. So, for example, the code would ask the user to input a string. A variable would then be created named after that string with a default value of "default". Is this even possible?
...
I am loading a component which makes a HTTPService call to get data that will then be used to set certain variables in the component. I make the HTTPService call in an init() function (for the initialization event) and then set the variables according to the data received in the HTTPService result handler. However, the variables are st...
So it's well known that you're supposed to call game's base.Initialize() before using the game object's GraphicsDevice right? That's what I gathered from reading a lot of tutorials online.
Apparently that's not where game's GraphicDevice is created because I'm able to use it before base.Initalize() like this...
protected override void ...
I have seen and done initialization of arrays and all put "nil" at the end of initialization but never question, why it is required to put there?
Plus if you are initializing your array in a loop, is it still necessary to put nil at the end of array? for example.
array = [[NSMutableArray alloc] init];
for (int i = 0 ; i < 10; i++)
{
...
I want to understand how to set the parameters of properties (accessors).
I took the following code from an example of Kal calendar.
// Holiday.h
@interface Holiday : NSObject
{
NSDate *date;
NSString *name;
NSString *country;
}
@property (nonatomic, retain, readonly) NSDate *date;
@property (nonatomic, retain, readonly) NSStri...
Hello...In a WinForms Application, when do I write the code to set the focus to a control both while the Application is launched and subsequently after I call a function.
For instance, if I have a DropDownList, a TextBox and 4 buttons and I want the Focus to be set to the DropDownList, where do I write my code?
To set the focus to a p...
Pretty clear in the title, I think. I'm not entirely sure on this, and I can't find a good answer via the Googles (alas, I haven't committed to the fine art of standards-fu), so I ask:
int i = x++, j = x++;
Is this defined? I am quite sure that i = x++, j = x++; as a normal statement would be undefined behavior is the comma operator, ...
I am creating a custom user control and I am wondering how do you set an initial value for a property during design time? I have a property called Alignment that has 4 enum values TopRight, TopLeft, BottomRight and BottomLeft. So, when a user drops the user control onto a Form, I want the initial value of the property to be always Bott...