c++

Is shared ownership of objects a sign of bad design?

Hi all, Background: When reading Dr. Stroustrup's papers and FAQs, I notice some strong "opinions" and great advices from legendary CS scientist and programmer. One of them is about shared_ptr in C++0x. He starts explaining about shared_ptr and how it represents shared ownership of the pointed object. At the last line, he says and I quo...

strange SDL memory usage depending on bits per pixel

I have a very simple SDL program that uses only 1MB of memory with 32 bits per pixel, 2.4MB with 24 bits per pixel, 1.9MB with 16 bits per pixel, and 1.4MB with 8 bits per pixel. what is with this strange memory usage? why does the most bits per pixel take up the least amount of memory? C++ GCC thanks ...

Two calls to destructor

For the following code: #include<iostream> #include<vector> #include<string> using namespace std; struct Test { string Str; Test(const string s) :Str(s) { cout<<Str<<" Test() "<<this<<endl; } ~Test() { cout<<Str<<" ~Test() "<<this<<endl; } }; struct TestWrapper { vector<Test>...

C++ unordered_map problem

This time I'm able to show a complete code: #include <unordered_map> #include <iostream> #include <stdlib.h> using namespace std; bool mystrcmp(const char *s1, const char *s2) { int i = 0; do { if(s1[i] != s2[i]) return false; } while(s1[i++] != '\0'); return true...

What is nothrow delete in C++?

This MSDN page mentions that there're nothrow versions of new and delete. nothrow new is quite a known thing - returns null instead of throwing an exception if memory allocation fails. But what is nothrow delete mentioned there? ...

Where to find a good tutorial and examples of CSOAP?

I started to work with CSOAP (see http://csoap.sourceforge.net) and when searched on google, I didn't find a good tutorial of CSOAP. Could you plz direct me to anything relevant from where to start? Thanks! ...

Associative array with multiple keys types, possible?

Ive got a large bunch of objects (potentially 1000's) which I need to store in a container. I need to be able to find specific instances in two ways, either by its ID number (64bit unsigned int), or its name (std::string). Generally by ID will be the most common, however in some cases the name is known, but not the ID. std::map can prov...

Intel® Atom™ Developer Program

I am a devlopere and i saw Intel® Atom™ Developer Program ads on stackoverflow. I have read the details but dont know if it is worth joining. Is it worh joining ?? http://appdeveloper.intel.com/en-us/ ...

Can anyone tell me about the Event Handler or Callback on switching of the front process on Mac?

I need to have the callback or some event handler which can help me, know front process is changed. Mac: C++/Carbon. Any help is highly appreciated. Thanks, Rahul ...

Which one to use - memmove() or memcpy() - when buffers don't overlap?

Using memcpy() when source and destination overlap can lead to undefined behaviour - in those cases only memmove() can be used. But what if I know for sure buffers don't overlap - is there a reason to use specifically memcpy() or specifically memmove()? Which should I use and why? ...

User management API

Hi, I am developing an application suite where users will need to connect to a server and depending on their account type they will be given some services. The server will run Linux. Can you please suggest me some user management API which I can use to develop the server program? By user management I mean user authentication and other r...

Any differences between f(const string &) and f(const string )?

class mystring { friend ostream& operator<<(ostream &out, const mystring ss) { out << ss.s; return out; } private: string s; public: mystring(const char ss[]) { cout << "constructing mystring : " << ss << endl; s = ss; } }; void outputStringByRef(const mystring &ss) { cout << "outputStri...

Multiple definitions of `GamepadControll::GamepadControll()'

I got this error message: multiple definition of `GamepadControll::GamepadControll()' After being frustrated for hours I reduced the code to: GamepadControll.h: #ifndef GAMEPADCONTROLL_H_ #define GAMEPADCONTROLL_H_ #include <iostream> class GamepadControll { public: GamepadControll(); virtual ~GamepadControll(); }; #en...

Where does execution resume following an exception?

In general, where does program execution resume after an exception has been thrown and caught? Does it resume following the line of code where the exception was thrown, or does it resume following where it's caught? Also, is this behavior consistent across most programming languages? ...

Can anyone recommend a good C/C++ RESTful framework

Rather than possibly reinventing the wheel (by "rolling my own") - I thought I'd ask in here first. Anyone knows where I can download a good C/C++ RESTful framework?. I have had a quick look on google, but there is nothing too impressive so far - maybe someone in here has written one already (that they dont mind sharing), or may know a ...

List of things to check to prevent VC++ applications from showing fatal error message boxes

Every now and then there's a strong need to write a program in such a way that it never (really never) shows an error message as a message box. For example it can be a program run inside a daily build - if it hangs with a message box the daily build hangs. Unfortunately VC++ runtime has a lot of ways to trigger message boxes when indica...

Time spent on reading from file

I am doing this in C++: if (myfile.is_open()){ while (! myfile.eof()){ getline (myfile,line); DO STUFF } myfile.close(); } else{ cout << "Unable to open file"; } I am trying to read the lines from a text file and do stuff with it. I am trying to see what the run t...

c++ node list - NULL test not working

I wanted to test the following code (which works fine for a non-null list) to see what would happen in the case of an empty list (in which case the head would be null). hence the code which applies to filling the list is commented out.. But for some strange reason, the test for NULL in print_nodes() just doesnt seem to work. ive added ...

length of array in c++

I read to get the length of array in C++, you do this: int arr[17]; int arrSize = sizeof(arr) / sizeof(int); I tried to do the same for a string: where I have string * arr; arr = new (nothrow) string [213561]; And then I do arr[k] = "stuff"; where I loop through each index and put "stuff" in it. Now I want the size of the array...

Different math rounding behaviour between Linux, Mac OS X and Windows

HI, I developed some mixed C/C++ code, with some intensive numerical calculations. When compiled in Linux and Mac OS X I get very similar results after the simulation ends. In Windows the program compiles as well but I get very different results and sometimes the program does not seem to work. I used GNU compilers in all systems. Some ...