c++

Does allowing a std::fstream to be destroyed close the associated file?

I'm wondering if I need an RAII wrapper around std::fstream.... ...

Runtime process memory patching for restoring state

I'm looking for a method for storing the process memory, and restore it later at certain conditions. ... Actually I've read questions about it... It seems a big challenge! So, let's analyse: The application is a distributed one, but many processes are stateless (request their state to a centralized server). Processes uses network conn...

Why does my setup.py script give this error?

So I have a C++ class that I made python wrappers for, and I made a setup.py file to compile it in order to use it in python. When I try to run python setup.py install I get the following error: lipo: can't create output file: build/temp.macosx-10.5-fat3-2.7/../tools/transport-stream/TransportStreamPacket_py.o (No such file or directory...

Identify C++ Socket port number

Ok, so I can create a socket and send a message to a remote machine (UDP btw). My problem is that I need to know what port I sent the message on. The remote machine is going to respond on the same port that I sent from. Right now it seems to be picking random high ports, like 46555. Is there a way to specify what port it goes out on or i...

static abstract methods in c++

I have an abstract base class class IThingy { virtual void method1() = 0; virtual void method2() = 0; }; I want to say - "all classes providing a concrete instantiation must provide these static methods too" I am tempted to do class IThingy { virtual void method1() = 0; virtual void method2() = 0; static virtual IThingy Fa...

Returning COM object to JScript

Hi. I am trying to pass a COM object from an ActiveX component to JScript. So far I have tried the following method of doing so: STDMETHODIMP CHSNetwork::CreateIPPPacket(VARIANT ** ppv) { IIPPacket *iipp; HRESULT hr = CoCreateInstance(CLSID_IPPacket, NULL, CLSCTX_ALL, IID_IIPPacket, (void **)&iipp); if(SUCCEEDED(hr) && ppv) ...

converting an integer to a std::string accepted by an std::pair

I have this function that converts an integer to a std::string: std::string intToStr(const int n) { stringstream ss; ss << n; return ss.str(); } It's worked well so far, but now I'm trying to construct a string to put into a std::pair, and I'm having some trouble. Given an integer variable hp and a function that returns a...

Should small simple structs be passed by const reference?

I have always been taught that non-primitive types should be passed by const reference rather than by value where possible, ie: void foo(std::string str);//bad void foo(const std::string &str);//good But I was thinking today that maybe actually some simple user defined types may actually be better passed by value eg: class Vector2 { ...

Is there a way to do a #define inside of another #define?

I know that I am trying to shoot myself in the leg ;) However, it will allow me to make the rest (big amount) of code smaller and more readable. Is there any tricky way to create preprocessor macro inside of another preprocessor macro? Here is the example, what I am looking for. My real scenario is more complex // That's what I want ...

exercise in the c++ programming language 3rd edition - desk calculator

I'm not sure what Bjarne meant with this exercise: "Convert the desk calculator to use a symbol structure instead of using the static variables number_value and string_value." Did he mean puting those 2 variables inside a structure and then using them through a structure? Edit: also one exercise related to the clculator and it says: "...

c++ member initialization list completeness

must class member initialization lists in c++ be complete? or can they simply initialize one or two of the member data in a class? thanks in advance! ...

Visual Studio - autogeneration files

I use in my c++ project google buffer protocol lib. And after changing *.proto files in my solution I need regenerate *.cpp files using google buffer protocol compiler. How can do it before compilation? Pre-buid events is not acceptable for me. ...

Ways to show your co-programmers that some methods are not yet implemented in a class when programming in C++

What approaches can you use when: you work with several (e.g. 1-3) other programmers over a small C++ project, you use a single repository you create a class, declare its methods you don't have a time do implement all methods yet you don't want other programmers to use your code yet (because it's not implemented yet); or don't want to ...

Can I force the C pre processor to generate a new line ?

Possible Duplicate: How can I make the preprocessor insert linebreaks into the macro expansion result? #define IDENTIFIER { /*new line here*/\ my_multiline(); /*new line here*/\ macro(); /*new line here*/\ } /*new line here*/ Can I force the C pre processor to generate a new line in it's expan...

Compile error when attemping to get value of QSqlQuery?

Just trying to mess around with Qt and SQLite to get familiar with how things work- I haven't really done DB programming since my vb6 days, so please be easy ;] I'm just trying to get the result of a query and I'm trying to follow some examples I found online (namely this one). The process seems simple enough: create the QSqlQuery objec...

maintaining sorted link list

Hi again, I'm trying to create and maintain a sorted link list. Every new element should be inserted in a way that the list remains sorted. I have been able to code it but am not too happy with my code. Basically there are 4 conditions that need to be satisfied according to me and in my attempt to achieve all of them i think i have ma...

Why do we use templates instead of functions?

Just looking for some good reasons so i could start learning about them :/ ...

How is dynamic_cast typically implemented?

Is the type check a mere integer comparison? Or would it make sense to have a GetTypeId virtual function to distinguishing which would make it an integer comparison? (Just don't want things to be a string comparison on the class names) EDIT: What I mean is, if I'm often expecting the wrong type, would it make sense to use something lik...

Why push a duplicate key when adding to a table in Lua?

I'm learning how to bind C++ objects to Lua with type checking from the book Programming Gems 6 (Chapter 4.2). For the type checking the userdata/string pairs are being stored in an environment table, with the code given how to do that: void Binder::pushusertype(void* udata, const char* tname) { lua_pushlightuserdata(L, udata); // push...

Typedef reinterpret_cast

Hi, I am having some trouble figuring out the syntax for typedef reinterpret_cast. Can anyone help? EDIT What I am trying to do. I am always hesitant as people seem to get caught up in every thing else except what the problem actually is as you can see with my last post which lead to a whole bunch of nothing. I am trying to come up w...