Hi,
i have an array (C language) that should be initialized at compile time.
For example:
DECLARE_CMD(f1, arg);
DECLARE_CMD(f2, arg);
The DECLARE_CMD is called from multiple files.
I want this to be preprocessed in.
my_func_type my_funcs [] = {
&f1,
&f2
}
It is possible, with a macro, to append items to an static array?
I...
In this simple example, why do I need to make 'member' const in order to get this to compile?
struct ClassA
{
ClassA(int integer) {}
};
struct ClassB
{
ClassB(int integer):
member(integer)
{
}
const ClassA& member;
};
int main()
{
ClassB* b = new ClassB(12);
return 0;
}
Otherwise, I get this err...
Entity has a member var of type std::array. Student inherits from Entity, and will need to initialize the std::array member var it inherited. Below is the code I'm using to do this, but it involves casting a brace-enclosed list to std::array. I'm not sure this is the correct or optimal way to do this. Using a brace-enclosed or double...
Are there any differences between the following ways of initialization of variables?
@var ||= []
@var = [] if @var.nil?
@var = @var || []
Please share your way initializing a variable and state the pros & cons.
...
Hi, I am trying to initialise an array from a file
This is the file containing an array of strings .. this is the xml file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<string>ccccc</string>
<string>ddddddd<...
I would like to know how to create an object of the specified Class in objective c. Is there some method I am missing in the runtime docs? If so what is it? I would like to be able to do something like the following:
NSDictionary *types;
-(id<AProtocol>) createInstance:(NSString *) name
{
if ((Class cls = [types objectForKey:name])...
I'm trying to figure out why this example doesn't compile. My understanding is that if a static variable is not explicitly set then it defaults to 0. In the five examples below four of them behave as I would expect, but the one that's commented out won't compile.
#include <iostream>
class Foo
{
public:
static int i;
static int ...
I kind of posted a similar question a couple of days ago but that was more geared towards any *.Designer.cs file. This question is geared towards declaration and initialization of global variables within a class. To my knowledge, it's almost common practice (aside from the *.Designer.cs files it seems) to place all global variables at ...
I'm with a doubt In initialization of this in C++:
char** A_Function()
{
char** charList = new char*[2];
charList[0] = "abcde";
charList[1] = "fghij";
return charList;
}
There's no problem "on compiling this code", but I'm not sure about the behaviour.
1 - the char list: char* is on heap ok?
2 - the charList[n_positio...
I'm writing some C and I have a lookup table of ints. I'm a little rusty... where do I declare and initialize the array so that I can use it in multiple C files? Can I declare it in an H file and initialize it in a C file?
...
Hi I'm having problem with initialization in java, following code give me compile error called : expected instanceInt = 100; but already I have declared it. If these things relate with stack and heap stuff please explain with simple terms and I'm newbie to java and I have no advanced knolwedge on those area
public class Init {
int...
I'd like to subclass an existing scons class (named SConsEnvironment) which has the following __init__ prototype:
def __init__(self,
platform=None,
tools=None,
toolpath=None,
variables=None,
parse_flags = None,
**kw):
In my own class...
If I have a class A with only a copy constructor and a constructor with parameters int and int, and I place that class inside a class B:
class B
{
public:
B();
private
A a;
}
How would I initialize a inside B's constructor?
I've tried a(0, 0), a = A(0, 0), but not surprisingly neither worked, and I receive a
error: no match...
It's been a long time since I worked with C++, but I have a class that uses 3-dimensional data and I can't figure out how I can make this work. I need the sizes of the dimensions to be defined in the constructor. I tried this in the header:
class CImage
{
public:
float values[][][];
...
}
and this in the constructor:
CImage::CIma...
I want to initialize a two-dimensional array of variable size to zero.
I know it can be done for a fixed-sized array:
int myarray[10][10] = {0};
but it is not working if I do this:
int i = 10;
int j = 10;
int myarray[i][j] = {0};
Is there a one-line way of doing this or do I have to loop over each member of the array?
Thanks
...
In C++0x, what I want would be:
std::list<std::string> colours = {"red", "blue", "green", "grey", "pink", "violet"};
What's the easiest way in standard, non-0x C++?
...
Hello SO,
I am a bit ashamed to ask that, being a Java programmer for years, but here goes:
Is there a difference between allocating objects during construction, and doing so directly when declaring the relevant field? That is, is there a difference between the following two:
public class MyClass{
MyObj obj=new MyObj();
}
AND
pu...
considering visual C++ compiler, Lets say I've got a file with whatever extension and it contains 100 bytes of data which are exactly the data that I want to initialize an array of char data type with a length of 100 characters with, Now apparently one way is to read those data out of file by using I/O file classes or APIs at run-time bu...
I'm writing a Python program with a GUI built with the Tkinter module. I'm using a class to define the GUI because it makes it easier to pass commands to buttons and makes the whole thing a bit easier to understand.
The actual initialization of my GUI takes about 150 lines of code. To make this easier to understand, I've written the __i...
Hi,
I am trying to initialize a 2D array of structs in C++, but am getting an error. Can someone please tell me what am I doing wrong? I have rechecked the braces and they seem to be fine.
My code:
struct CornerRotationInfo {
bool does_breed;
int breed_slope;
bool self_inversion;
int self_slope;
inline CornerRotationInfo(b...