I am reading The thread building block book. I do not understand this piece of code:
FibTask& a=*new(allocate_child()) FibTask(n-1,&x);
FibTask& b=*new(allocate_child()) FibTask(n-2,&y);
What do these directive mean? class object reference and new work together? Thanks for explanation.
The following code is the defination...
int main(){
Employee *e = new Employee();
delete e;
delete e;
...
delete e;
return 0;
}
...
Hello:
How can I break long lines when writing c++ code in vim? For example, if I have something like
56 fprintf(stderr, "Syntax error reading recursion value on
57 line %d in file %s\n", line_count, filename);
I get the following compile errors:
:56:25: warning: missing terminating " character
:56: error: missing te...
Hi, what does the 0x80 code mean when referring to the keyboard controls in C++ Windows environment?
For example,
if(GetKeyState('K') & 0x80) {
//do something
}
Thanks everyone!
...
I have an application, currently written in C#, which can take a Base64-encoded string and turn it into an Image (a TIFF image in this case), and vice versa. In C# this is actually pretty simple.
private byte[] ImageToByteArray(Image img)
{
MemoryStream ms = new MemoryStream();
img.Save(ms, System.Drawing.Imaging...
I'm building an open source 2D game engine called YoghurtGum. Right now I'm working on the Android port, using the NDK provided by Google.
I was going mad because of the errors I was getting in my application, so I made a simple test program:
class Base
{
public:
Base() { }
virtual ~Base() { }
}; // class Base
class Vehic...
Hi:
I am trying to read from a file using fgets and sscanf. In my file, I have characters on each line of the while which I wish to put into a vector. So far, I have the following:
FILE *fp;
fp = fopen(filename, "r");
if(!fp)
{
fprintf(stderr, "Unable to open file %s\n", filename);
return 0;
}
// Read file
int line_...
I have a doubt concerning declaring variables, their scope, and if their address could be sent to other functions even if they are declared on the stack?
class A{
AA a;
void f1(){
B b;
aa.f2(&b);
}
};
class AA{
B* mb;
f2(B* b){
mb = b;
//...
}
};
Afterwards, I use my AA::mb pointe...
Cannot convert from "void" to "int" in C++ - anyone know why? is there a function i have to use?
int calc_tot,go2;
go2=calculate_total(exam1,exam2,exam3);
calc_tot=read_file_in_array(exam);
...
Is there a difference between the following approaches?
// approach 1
namespace std
{
template<>
void swap<Foo>(Foo& x, Foo& y) // note the <Foo>
{
x.swap(y);
}
}
// approach 2
namespace std
{
template<>
void swap(Foo& x, Foo& y)
{
x.swap(y);
}
}
I stumpled upon this when I tried to s...
I have a C++ function that produces a list of rectangles that are interesting. I want to be able to get that list out of the C++ library and back into the C# application that is calling it.
So far, I'm encoding the rectangles like so:
struct ImagePatch{
int xmin, xmax, ymin, ymax;
}
and then encoding some vectors:
void MyFunc(....
If i have a header file foo.h and a source file foo.cpp, and foo.cpp contains something along the lines of:
#ifdef WIN32
class asdf {
asdf() { startup_code(); }
~asdf() { cleanup_code(); }
};
asdf __STARTUP_HANDLE__
#else
//unix does not require startup or cleanup code in this case
#endif
but foo.h does not define class asdf, sa...
I decided that I want to make a game for the iphone I was thinking of using oolong or sio2 any recommendations?
Both have the problem of lack of tutorials, is it possible to somehow use a normal C++ game tutorial and integreate the engines rather than the one used in the tutorials? So if the C++ tutorial talks of creating an engine I c...
Hey,
I've been working on an async boost server program, and so far I've got it to connect. However I'm now getting a "Vector iterator not dereferencable" error.
I suspect the vector gets destroyed or dereferenced before he packet gets sent thus causing the error.
void start()
{
Packet packet;
packet.setOpcode(SMSG_PING);
...
I'm wanted to convert some of my python code to C++ for speed but it's not as easy as simply making a C++ function and making a few function calls. I have no idea how to get a C++ integer from a python integer object. I have an integer which is an attribute of an object that I want to use. I also have integers which are inside a list in ...
If I am making a proxy factory, can I just make the outgoing request saying Proxy::HTTP (there's a similar enum for SOCKS) and the SOCKS5 proxy server should automatically detect and handle that correctly, right?
...
I'm currently designing a object structure for a game, and the most natural organization in my case became a tree. Being a great fan of smart pointers I use shared_ptr's exclusively. However, in this case, the children in the tree will need access to it's parent (example -- beings on map need to be able to access map data -- ergo the dat...
i have no idea how to get these errors out. i wrote the whole code over and tried to see if it was a problem with brackets but that doesnt help either. i dont know what line it is but i believe it is in this function.
error LNK2019: unresolved external symbol "int __cdecl read_file_in_array(int (* const)[3])" (?read_file_in_array@@YA...
In C++, the common practice is to declare functions in header files and define them in cpp files. This leads to always having two copies of every function's prototype. Then whenever I want to change a function's name/return value/parameter, I have to manually change it in both files. This seems unnecessarily tedious and there must be lot...
this program runs but not correctly numbers arent right, i read numbers from a file and then when i am using them in the program they are not right.:brief decription of what i am trying to do can someone tell me if something doesnt look right.
this is what i have to do:
write a program that determines the grade dispersal for 100 studen...