c++

stl vector memory management

Hello, I am using borland 2006 c++, and have following code. I am using vectors, and have trouble understanding why the destructor is not being called. basically i have a class A class A { private: TObjectList* list; int myid; public: __fastcall A(int); __fastcall ~A(); }; __fastcall A::A(int num) { myid = num; list...

C++/OpenGL - Rotating a rectangle

Hi, For my project i needed to rotate a rectangle. I thought, that would be easy but i'm getting an unpredictable behavior when running it.. Here is the code: glPushMatrix(); glRotatef(30.0f, 0.0f, 0.0f, 1.0f); glTranslatef(vec_vehicle_position_.x, vec_vehicle_position_.y, 0); glEnable(GL_TEXTURE_2D); glEnable(GL_B...

VS2008 internal compiler error

I'm consistently running into an internal compiler error while attempting to switch from MSVC6 to MSVC 2008. After much work commenting out different parts of the program, I've traced the error to two lines of code in two different CPP files. Both of these CPP files compile successfully, yet somehow have an effect on whether or not the...

Free C++ lib (Win32) to record microphone

Hey there, is there any recommendation for a library (c++, Win32, open source) to get the sound from a microphone? Thanks ...

Programatically getting UID and GID from username in Unix?

I'm trying to use setuid() and setgid() to set the respective id's of a program to drop privileges down from root, but to use them I need to know the uid and gid of the user I want to change to. Is there a system call to do this? I don't want to hardcode it or parse from /etc/passwd . Also I'd like to do this programatically rather tha...

Is it possible to get early/static binding using function pointers in c++? If yes then how?

In C++, one way to get late/dynamic binding is to use function pointers we can also use virtual functions. But don't know about the early/static binding. ...

stl vectors add sequence

Hello , Iam using borland 2006 c++ class A { private: TObjectList* list; int myid; public: __fastcall A(int); __fastcall ~A(); }; __fastcall A::A(int num) { myid = num; list = new TObjectList(); } __fastcall A::~A() { } int main(int argc, char* argv[]) { myfunc(); return 0; } void myfunc() { vector<A> vec;...

How do I make a file self-update (Native C++)

I'm using Microsoft Visual Studio 2008 with a Windows target deployment. How would I make a file "update itself"? I've already got the "transmitting over a network" part down, but how do I make an executable write over itself? Basically, I want to write an auto-updater for a directory that also includes the auto-updater, and the updater...

Can assignment be done before constructor is called?

A comment to http://stackoverflow.com/questions/945232/whats-wrong-with-this-fix-for-double-checked-locking says: The issue is that the variable may be assigned before the constructor is run (or completes), not before the object is allocated. Let us consider code: A *a; void Test() { a = new A; } To allow for more for...

How do I convert something of "string*" to "const string&" in C++?

For example, if I have the following: void foo(string* s) { bar(s); // this line fails to compile, invalid init. error } void bar(const string& cs) { // stuff happens here } What conversions do I need to make to have the call the bar succeed? ...

Eye-Tracking library in C#, C/C++ or Objective-C

Anyone know of an eye-tracking library for C#, C/C++ or Objective-C? Open-source is preferable. Thanks. ...

How to debug heap corruption errors?

I am debugging a (native) multi-threaded C++ application under VS2008. On seemingly random occasions, I get a "Windows has triggered a break point..." error with a note that this might be due to a corruption in the heap. These errors won't always crash the application right away, although it is likely to crash short after. The big probl...

MFC: CButton highlighting for a group of radio buttons

I know that I can create an integer variable for a group of radio buttons, set it to an integer, and then call UpdateData(FALSE) to make the window highlight the appropriate radio button control. However, I would like to perhaps use a CButton control instead, but I don't know how to set the CButton state so that a particular radio button...

Multiple inheritance hierarchy

I'm looking for a clean way of doing this since a long time. In my problem, there exist 3 classes not sharing any parent in common but each having some methods with the same name (A.doSomething, B.doSomething, C.doSomething). Hence, having the same function signature, class D inheriting from A and using method doSomething() will "look th...

Changing return type of a function without template specialization. C++

I was wondering if it is possible to change the return type of a function based on the type of variable it is being assigned to. Here's a quick example of what I mean. I want to create a function that parses a variable of int, bool, or float from a string. For example... Int value = parse("37"); Float value = parse("3.14"); Bool value ...

I'd like to port simple C++ echo server to C#

SOCKET client = accept(listen_sock, 0, 0); timeval client_to; client_to.tv_sec = 1; client_to.tv_usec = 0; setsockopt(client, SOL_SOCKET, SO_RCVTIMEO, (char*)&client_to, sizeof(client_to)); char buffer[1024]; while ((ret = recv(client, buffer, 1024, 0)) != 0) { cout << "<in loop>" << endl; if (ret == -1 && WSAGetLastErr...

What encoding does std::string.c_str() use?

I am trying to convert a C++ std::string to UTF-8 or std::wstring without losing information (consider a string that contains non-ASCII characters). According to http://forums.sun.com/thread.jspa?threadID=486770&amp;forumID=31: If the std::string has non-ASCII characters, you must provide a function that converts from your encoding ...

String to Integer Hashing Function with Precision

Hi, I want to hash a char array in to an int or a long. The resulting value has to adhere to a given precision value. The function I've been using is given below: int GetHash(const char* zKey, int iPrecision /*= 6*/) { /////FROM : http://courses.cs.vt.edu/~cs2604/spring02/Projects/4/elfhash.cpp unsigned long h = 0; ...

C++: How to Convert From Float to String Without Rounding, Truncation or Padding?

I am facing a problem and unable to resolve it. Need help from gurus. Here is sample code:- float f=0.01f; printf("%f",f); if we check value in variable during debugging f contains '0.0099999998' value and output of printf is 0.010000. a. Is there any way that we may force the compiler to assign same values to variable of float ty...

see previous definition of 'some symbol'

while programming in c++, Most of the times i get 'some symbol' has already been defined see previous definition of 'some symbol' I think this happens because improper order of headers file included. How can i find out all the definitions of 'some symbol' Thanks in advance, Uday EDIT: I am using visual studio I remember some comma...