c++

Does itoa delete char?

Why does this give me a memory error? char* aVar= new char; itoa(2, aVar, 10); delete aVar; Does itoa delete the aVar? How to know if a C++ function deletes the pointer, is there a convention about that? If I do this then error doesn't occur: char* aVar= new char; delete aVar; ...

is there some kind of object representation software that you can control remotely through some kind of api?

What it should do is represent objects of various types, but you should be able to control the representation remotely through some network-based api from another application (xml idealy). What I want to do is to have the logic of my application written in C++, where many kinds of "objects" are involved. I'd like to be able to manage the...

C++: malloc : error: invalid conversion from ‘void*’ to ‘uint8_t*’

Hi, I got this problem: invalid conversion from ‘void*’ to ‘uint8_t*’ When doing this: int numBytes; uint8_t *buffer; buffer=malloc(numBytes); //error here, why? or must I have to put it like this? buffer=malloc(numBytes); Please explain... Thanks in advance. ...

Why does storing references (not pointers) in containers in C++ not work?

In my program I have a STL set. set<string> myStrings; To improve efficiency I changed it to only hold pointers. (I don't need actual string copies to be stored.) set<string*> myStrings; I read that it is a good practice to substitute pointers with references when possible. (Of course only if the actual functionality of a pointer i...

How to use a C++ library in a C# app?

Thus far I've figured out out I needed to recompile the library as a .dll instead of a .lib, enable /clr and /EHa instead of /EHsc. Now I've got a managed dll which I've added as a reference in my C# project. Now how do I use it? I'm prepared to write some wrappers, but I don't know where to begin or how to "see" what functions I've ga...

How does one use multiple files with an AudioQueue?

Hey everyone, I'm just looking thought the apple iOS example "SpeakHere" http://developer.apple.com/library/ios/#samplecode/SpeakHere/Listings/Classes_AQPlayer_mm.html%23//apple_ref/doc/uid/DTS40007802-Classes_AQPlayer_mm-DontLinkElementID_12 and I was wondering what's the best approach for using the above, but with two audio files, so ...

Object Oriented c++ Question

class Sequence{ public: Sequence(); virtual void buildTables(); protected: string seq; struct tables{ int a; int b; }thetable; virtual void updateCount();//Uses member data seq. sorry. about the confusion. } void Sequence::buildTabeles(){ for (int i = 0; i < seq.length...

Qt Tray Icon Drag and Drop

Does anyone know if it is possible to use drag and drop with a tray icon using Qt? ...

How does this code work?

I found this piece of C++ code on a forum that I can't fully understand. Since I don't have their library that performs matrix/vector math, I need to manually figure it out and replicate the functionality. Calculate Euler rotation angles between 2 vectors .. we use Rodrigues formula vector $V1 = << my first vector >>; vector $V...

placement new + array +alignment

SomeObj<unsigned int>* Buffer; char* BufferPtr = MemoryManager::giveMeSomeBytes(resX*resY*sizeof(SomeObj<unsigned int>)); Buffer = new(BufferPtr) SomeObj<unsigned int>[resX*resY]; when I step past these lines with the debugger, it shows me the values for the variables Buffer and BufferPtr: BufferPtr: 0x0d7f004c Buffer: 0x0d7f0050 ...

Seperating template class into multiple files yields linking issues

I have created an example below to illustrate the problem I'm having. Basically, when I separate a template class into separate .h/.cpp file, I get unresolved symbols for the constructor. Using a single file, it compiles fine. What is causing this? fruits.cpp: #include "apple.h" class FruitsDB { public: void addApple();...

How to prevent copying a wild pointer string

My program is crash intermittently when it tries to copy a character array which is not ended by a NULL terminator('\0'). class CMenuButton { TCHAR m_szNode[32]; CMenuButton() { memset(m_szNode, '\0', sizeof(m_szNode)); } }; int main() { .... CString szTemp = ((CMenuButton*)pButton)->m_szNode; // sometime it crashes he...

c++ socket stream api

I'm using what looks to be a real nice API for streaming sockets found here: http://www.pcs.cnu.edu/~dgame/sockets/socketsC++/sockets.html. I'm having trouble accessing the IP of the connected user because its a private member of a class "Socket" that is used within another class "ServerSocket". My program looks exactly like the demo on...

Is pointer better than instance when declaring members in class?

Option 1: class B{//}; class A { public: void Funcs(); private: std::vector<A> vecA; }; Option2: class B{//}; class A { public: void Funcs(); private: std::vector<A*> vecpA; }; Which one is better, is there any guidelines? ...

How can I call a C++ function from C?

I have a header declaring functions that take pointers to C++ objects as parameters. The implementaton is in a seperate C++ file. How can I include this header in C and use the functions in C even though the arguments need to be C++ object pointers? ...

How to compile Box2D for C# with SWIG?

I'm trying to compile Box2D for use in C# with SWIG. I've created this Box2D.i file, %module Box2D %{ #include "Box2D/Box2D.h" %} %include "Box2D/Box2D.h" Which I placed one level up from the Box2D.h file file, and "compiled" it with, swig.exe -csharp -c++ -includeall -ignoremissing -outdir SWIG Box2d.i This gives me all the .cs ...

Overload comparison operators for a templated class

Hi experts, I'm having troubles in overloading comparison operators in order to compare two pair struct in such way: typedef pair<string, unsigned int> INDEX; bool operator>(INDEX &v1, INDEX &v2) { if(v1.second == v2.second) //if integer parts are equal { //string that comes earlier in the dictionary should be larger ...

Memory ordering issues

I'm experimenting with C++0x support and there is a problem, that I guess shouldn't be there. Either I don't understand the subject or gcc has a bug. I have the following code, initially x and y are equal. Thread 1 always increments x first and then increments y. Both are atomic integer values, so there is no problem with the increment ...

How to avoiding writing switch-case too long?

In my current project, there are lots of code using switch statements with too many cases. Switch(c) { case CASENUMBERONE: //50-100 lines of code in each code ... case CASENUMBERTWENTY: .. } //thousands of lines of macro definition in another file #define CASENUMBERONE 1 ... #define CASENUMBERTWENTY 20 ... It seems not reasonable p...

EXE and DLL dependency - When to recompile the EXE?

Hi All, I've the following class definitions in exe and dll. // A.exe: Class A { void fun() { B* b = new B(); b.funx(); } // B.dll: Class B { void funx (void) { C* y = new C(); y.funy(); } Class C { void funy() { } } Lets say I change the size of class B, should i recompile A.exe? And should I recompile A.exe even if I change size...