c++

C++ concept check vs inheritance

What is the relationship between using virtual functions and C++ inheritance mechanisms versus using templates and something like boost concepts? It seems like there is quite an overlap of what is possible. Namely, it appears to be possible to achieve polymorphic behavior with either approach. So, when does it make sense to favor one ov...

on languages that can link to c++

As I was reflecting on this subject, it seemed to me that if a language is implemented in C++, it might well have a mechanism for linking to C++. As I recall, Java is this way through JNI, though I don't really remember if it goes through C++ or plain C. However, it seems that in general languages don't link to C++, and are accessible t...

Comparing string data received from a socket in C

I have a question on sockets. I have this code: while(bytes = recv(sClient, cClientMessage, 599, 0)){ This puts the message it recives into cClientMessage and the message is always "Message". How I made an if statement like if(cClientMessage == "Message"){//do func}. Now this code will not do the function I want. I think this is b...

How to restart a sockets program?

I need my server to stay connected to the server. Does anyone know how to do this? Or post links tutorials anything? Also it says when it restarts 'could not accept client' so how would I clear everything and make it accept it? ...

NULL pointer with boost::shared_ptr?

What's the equivalent to the following: std::vector<Foo*> vec; vec.push_back(NULL); when dealing with boost::shared_ptr? Is it the following code? std::vector< boost::shared_ptr<Foo> > vec; vec.push_back(boost::shared_ptr<Foo>()); Note: I may push back a lot of such objects. Should I declare a global static nullPtr object somewhere...

How to intentionally delete a boost::shared_ptr?

I have many boost::shared_ptr<MyClass> objects, and at some point I intentionally want to delete some of them to free some memory. (I know at that point that I will never need the pointed-to MyClass objects anymore.) How can I do that? I guess you can't just call delete() with the raw pointer that I get with get(). I've seen a functio...

Force screen redraw after drawing to screen's DC C++

I'm creating a Windows Mobile custom SIP and as the user presses or "hovers" over a button on the keyboard I draw it's corresponding selected image (iPhone-esque) to the screen's DC using ::GetDC(NULL). It is developed in Win32 C++. My problem is that I can never get the screen to repaint itself, erasing the previously drawn key. I'v...

How to run a Qt application?

I have been using Qt creator to make applications using the Qt libraries. I can run these applications by just clicking the play button, but I want to learn how to make applications run just by double clicking on a .exe. So how can I do this? ...

How do you get a file in C++?

So the teacher has posed this assignment: You have been hired by the United Network Command for Law Enforcement, and you have been given files containing null cyphers you have to decrypt. So for the first file given (as an example), every other letter is correct (ie: 'hielqlpo' is hello (assuming you start with the first letter). My f...

from C++ to C#

What are good c++ to C# articles/tutorial or books? I am reading http://msdn.microsoft.com/en-us/magazine/cc301520.aspx and will read http://andymcm.com/csharpfaq.htm and http://www.ondotnet.com/pub/a/dotnet/2002/02/11/csharp_traps.html afterwards. Have any of you read any good books for ppl who have a strong understanding of programming...

More efficient way to reuse vector as array in winsock?

Hi, I'm currently using vectors as c-style arrays to send and recieve data through Winsock. I have a std::vector and I'm using that as my 'byte array'. The problem is, I'm using two vectors, one for each send, and one for each recv, but what I'm doing seems to be fairly inefficient. Example: std::string EndBody("\r\n.\r\n"); std::fil...

What are data breakpoints?

I just came to know that there are data breakpoints. I have worked for the last 5 years in C++ using Visual Studio, and I have never used data breakpoints. Can someone throw some light on what data breakpoints are, when to use them and how to use them with VS? As per my understanding we can set a data breakpoint when we want to check f...

Compilers and argument order of evaluation in C++

Okay, I'm aware that the standard dictates that a C++ implementation may choose in which order arguments of a function are evaluated, but are there any implementations that actually 'take advantage' of this in a scenario where it would actually affect the program? Classic Example: int i = 0; foo(i++, i++); Thanks. Note: I'm not look...

How new keyword works in c#

There's a class which is compiled into a dll //HeaderFile.h //version 1.0 class __declspec(dllexport) A { int variable; //member functions omitted for clarity }; //implementation file omitted for clarity You build an exe which uses above class from the dll it was compiled into #include "HeaderFile.h" int main() { A *obj = ...

C++: What is the size of an object of an empty class?

I was wondering what could be the size of an object of an empty class. It surely could not be 0 bytes since it should be possible to reference and point to it like any other object. But, how big is such an object? I used this small program: #include <iostream> using namespace std; class Empty {}; int main() { Empty e; cerr <<...

ofstream error

This is in reference to another question I asked, though it is its own question entirely. when I compile I get two errors: 1>.\asst4.cpp(73) : error C2065: 'outfile' : undeclared identifier 1>.\asst4.cpp(73) : error C2228: left of '.close' must have class/struct/union I'm slightly confused as to what I've done incorrectly here? Any r...

Can a single SetEvent() trigger multiple WaitForSingleObject()

This: http://msdn.microsoft.com/en-us/library/ms686915(VS.85).aspx Would seem to suggest not. I have three processes communicating via pipes. Process A Creates an event, Process B & C each use WaitForSingleObject (in a second thread). So now we have -TWO- Processes each waiting for a -SINGLE- event. Process A fires the event with Se...

Signaling an error in file streams in C++

Hello! I have got the following sample: #include <iostream> #include <fstream> using namespace std; int main() { ifstream file; cout << file << endl; // 0xbffff3e4 file.open("no such file"); cout << file << endl; // 0 cout << (file == NULL) << endl; // 1 cout << file.fail() << endl; // 1 }...

How to reduce CPU usage of a program?

I wrote a multi-threaded program which does some CPU heavy computation with a lot of floating point operations. More specifically, it's a program which compares animation sequences frame by frame. I.e. it compares frame data from animation A with all the frames in animation B, for all frames in animation A. I carry out this intensive ope...

[C++ stl] list of public functions/classes with their corresponded header files

I tried to find a place where I can find ready to copy list of all functions and classes available in each stl header file. Looking through /usr/include/c++ is not so convenient as I expected. Google very often shows http://www.cplusplus.com/reference/ which is not so convenient to copy and paste. Does anyone knows a good place to lo...