c++

C++ Array vs vector

when using C++ vector, time spent is 718 milliseconds, while when I use Array, time is almost 0 milliseconds. Why so much performance difference? int _tmain(int argc, _TCHAR* argv[]) { const int size = 10000; clock_t start, end; start = clock(); vector<int> v(size*size); for(int i = 0; i < size; i++) { for(int j = 0; j < size; j+...

C++ - What should go into an .h file?

When dividing your code up into multiple files just what exactly should go into an .h file and what should go into a .cpp file? ...

Visual C++ 2008 Issues

Okay, this is getting stupid, I have Microsoft Visual Studio 2008, was working fine, now whenever I run a .cpp program my command prompt windows has a default color of gray when I initially had lime green for the output. Error Message: 'Testing.exe': Loaded 'C:\Users\codebox\Documents\Visual Studio 2008\Projects\Testing\Debug\Testing.e...

What could this curious combination of "while" and "delete" mean?

Reviewing a quite old project I found the following curious code snippet (only relevant code extracted): class CCuriousClass { ~CCuriousClass(); CSomeType* object; }; CCuriousClass::~CCuriousClass() { while( object != NULL ) { delete object; } } Have I overseen anything or is it a plain road to undefined behav...

Need Good C++ Libraries For Strings & HTTP Streams

Hi, I'll soon be starting a project of mine that heavily involves reading and interacting with websites. So I'd like to start pulling in some decent libraries to cut down on some of the dirty work that needs to be done in C++. Thus far I've found 'The Better String Library' for string manipulation. Any other suggestions? ...

Rotation of camera used for perspective projection

I've just started playing with OpenGl to render a number of structure each comprising a number of polygon. Basically I want to perform the equivalent of setting a camera at (0,0,z) in the world (structure) coordinates and rotate it about the x,y and z-axes of the world axes (in that order!) to render a view of each structure (as I under...

Is there better way to write do-while(0) construct to avoid compiler warnings?

I'm often use do-while(0) construct in my #defines, for the reasons described in this answer. Also I'm trying to use as high as possible warning level from compiler to catch more potential problem and make my code more robust and cross-platform. So I'm typically using -Wall with gcc and /Wall with MSVC. Unfortunately MSVC complain about...

Media file can not be switched and played

I am trying to play a music file on S60 5th edition with the following code: _LIT(KMusicFilename, "C:\\Data\\Music.mp3"); TApaTaskList iTaskList(CCoeEnv::Static()->WsSession()); TBool iExists; TApaTask iApaTask = iTaskList.FindApp(TUid::Uid(0x102072C3)); iExists = iApaTask.Exists(); if(iExists) { // Music player already run...

Multidimensional variable size array in C++

hi I want to do something like this: int op(string s1, string s2){ int x = s1.size(); int y = s2.size(); int matrix = new int[x][y] /* do stuff with matrix */ } For some reason I get the following errors: SuperString.cpp(69) : error C2540: non-constant expression as array bound SuperString.cpp(69) : error C2440: 'init...

inverse of matrix in c++

Possible Duplicates: Defining a matrix as an array of arrays and computation its inverse matrix in C++ Simple 3x3 matrix inverse code (C++) how to find a inverse of matrix in c++ . simple coding just to find inverse of 3by3 matrix and also for 4 by 4 matrix ...

How add objects dynamically

This is the question : How to do IT Right ? IT = add objects dynamically (mean create class structures to support that) class Branch { Leaves lv; //it should have many leaves!! } class Tree { Branch br; //it should have many branchs!!! } Now a Non-Working Example (neither is c++ !!, but I t...

Streaming videos from mobile phones.

I'm searching for open source libs for Streaming videos from mobile phones (from cameras on mobile phones) to servers. JAVA or C/C++ any one knows any? ...

Shared common definitions across C/C++ (unmanaged) and managed C# code

Hi, I have a set of struct definitions that are used by both C# managed components and unmanaged C/C++ components. Right now, the identical struct definitions exist separately in C/C++ and C# code - causing duplication and related chaos. What's the best way to maintain single definitions that can be used from both C# and C/C++? Thanks! ...

Pointing to the first object in a linked list, inside or outside class?

Which of these is a more correct way to store the first object in a linked list? Or could someone please point out the advantages/disadvantages of each. Thanks. class Node { int var; Node *next; static Node *first; Node() { if (first == NULL) { first = this; next = NULL; ...

Is boost tuple mutable?

I have been using a using a boost tuple as the value in an STL map. Up until now, I only had to construct the tuple and insert into the map and at a later stage retrieve the values. Now I need to be able to change the tuple in the map. Is this possible, or have I run into the one place you should'nt be using tuples instead of structs. ...

How to implement speech recognition and text-to-speech in C++?

I want to know about various techniques to do speech recognition and text to speech conversion. Also please let me know about any resources like links, tutorials ,ebooks etc. on it. Which is the most efficient technique to achieve it ? ...

How to handle required default constructor

In writing a copy constructor for one of my classes ( which holds a few objects of other UDTs ), I am required to create a default constructor for those UDTs, even though they were never really meant to have one. Is it fine to just implement a blank default constructor and be done with it? The only time the default constructor is invoke...

Predict C++ program running time

How to predict C++ program running time, if program executes different functions (working with database, reading files, parsing xml and others)? How installers do it? ...

Why is g++ saying 'no match for ‘operator=’ when there clearly is, and Visual Studio can see that there is?

I'm writing an interface library that allows access to variables within tables (up to a theoretically infinite depth) in an object of type regula::State. I'm accomplishing this by overloading operator[] within a class, which then returns another of that same class, and calls operator[] again as needed. For example: regula::State t; t["m...

Function Pointer Calls

Let's say there is an imaginary operating system... There is a function in it called settime that gets a pointer to function and a timestamp. The catch is that every time the function is called it runs over the last call (so only the new function being provided as parameter will be called). I want to expose a new function to my users ...