I have this small class called City that simply holds some information about a city, here it is:
class com.weatherwidget.City {
var zipCode:String;
var forecastText:Array = new Array(5);
}
When I have an array of cities and I change one of the forecastText of one city it will change that forecastText for all of the cities.
Fo...
I have a 2-dimensional jagged array (though it's always rectangular), which I initialize using the traditional loop:
var myArr = new double[rowCount][];
for (int i = 0; i < rowCount; i++) {
myArr[i] = new double[colCount];
}
I thought maybe some LINQ function would give me an elegant way to do this in one statement. However, the c...
Doesn't object initialization outside of a constructor break encapsulation ?
Given:
class MyClass
{
public string _aString;
}
Shouldn't the _aString member be private and instantiated via a call to the constructor (constructor omitted here):
MyClass test = new MyClass("test");
Instead of the alternate method of object in...
Within the same compilation unit, the C++ standard says that static initialization order is well defined -- it's the order of the declarations of the static objects. But using the Sun Studio 12 compiler I'm encountering unintuitive behavior. I've define a templated class helper<T> which contains a static member _data of type T and a stat...
How do I create and initialize an array in F# based on a given record type?
Suppose I want to create an Array of 100 record1 records.
e.g.
type record1 = {
value1:string;
value2:string
}
let myArray = Array.init 100 ?
But it appears the Array.init does not allow for this, is there a way to do this?
Edited to add:
Of course I ...
Here is some code outlining a problem I've been wrestling with. The final problem (as far as g++ is concerned at the moment) is that: "error: 'Foo-T' was not declared in this scope" when performing the Bar::Bar(...) constructor routine. Otherwise, the problem I'm attempting to learn my way through is one of setting base-class member type...
If I have the following code:
public class MyClass
{
public string myName { get; private set; }
public string myId { get; set; }
}
A private compiler-generated variable is created for the setter. I want the setter not to be accessible for object initialization only. But, how do I get to initially set the myName variable?
Rea...
I found this piece of code on Wikipedia.
#include <stdio.h>
int main(void)
{
int c;
while (c = getchar(), c != EOF && c != 'x')
{
switch (c)
{
case '\n':
case '\r':
printf ("Newline\n");
break;
default:
printf ("%c",c);
}
}
return 0;
}
I'm curious about expression ...
1.
I know that it is possible to initialise an array of structures in the declaration. For example:
struct BusStruct
{
string registration_number;
string route;
};
struct BusStruct BusDepot[] =
{
{ "ED3280", "70" },
{ "ED3536", "73" },
{ "FP6583", "74A" },
};
If the structure is changed into a class, lik...
Say I have a class with a field that needs to be initialized when the object is initialized. Such as list that need to be created before objects can be added/removed from it.
public class MyClass1
{
private List<MyOtherClass> _otherClassList;
public MyClass1()
{
this._otherClasslist = new List<MyOtherClass>();
}...
Is it good practice to initialize a global variable in PHP? The snippet of code seems to work fine, but is it better to initialize (in a larger project, say for performance sake) the variable outside of a function, like in the second scratch of code?
if(isset($_POST["Return"]))Validate();
function Validate(){
(!empty($_POST["From"])...
I've read in many places that you should always initialize Objective-C objects like so:
- (id) init {
if (self = [super init]) {
....
}
return self;
}
Because the super's init method may return a separate object from the current self.
Now I'm trying to do something like this, and I'm not sure if I have it right, v...
So I'm a bit rusty getting back into programming and I can't seem to find a good reference for understanding the structure for what I am trying to achieve. So, without further ado I am looking at creating and Class object such as.
#import Assets.h
@interface MainRecord: NSObject {
Assets* assets;
...
}
...
@end
Having a class...
What's the difference between these two methods of initializing the observers ArrayList. Or any other type for that matter. Is one faster than the other? Or am I missing some other benefit here.
class Publisher implements Observerable
{
private ArrayList observers = new ArrayList();
}
class Publisher implements Observerable
{
...
Please, help me to create a nested struct with an array. How do I fix this code?
class CMain
{
public:
CMain();
~CMain();
private:
struct
{
CCheckSum() : BufferSize(500) {memset(Buffer, 0, BufferSize);}
const int BufferSize;
char Buffer[BufferSize];
}Sm...
Can I launch a Java WebStart application with a set of parameters just like an applet is configured with the <param> tags ?
Thanks
...
Inside XNA struct Vector2 are two public variables X and Y.
I have the following code:
Vector2 v;
if(b) v.X=1;
else v.Y=2;
//use v
The compiler gives "Use of unassigned local variable 'v'"
But it runs correctly nonetheless.
Is there a more correct way of doing it?
...
I find in my PHP pages I end up with lines and lines of code that look like this:
$my_id = isset($_REQUEST['my_id']) ? $_REQUEST['my_id'] : '';
$another_var = isset($_REQUEST['another_var']) ? $_REQUEST['another_var'] : 42;
...
Is there a better, more concise, or more readable way to check this array and assign them to a local variabl...
Hi, I'm learning to develop for iPhone without Interface Builder (a personal preference), and I'm not sure which function of a view controller I should be setting up the view in: init, viewDidLoad, or loadView. I read somewhere to only use init for the view controller, if anything, and not setting up the view as it could cause problems. ...
There doesn't seem to be a standard constructor so I've taken to doing the following
void myMethod(char delimiter = ',')
{
string delimiterString = 'x';
delimiterString[0] = delimiter;
// use string version ...
}
Is there a better way to do this?
...