c++

Is it possible to change display for a typedef long MyType by using autoexp.dat?

I have type which is just a typedef-ed long which one I would like to display differently in a debugger. Is it possible to do so using autoexp.dat? namespace MyNamespace { typedef long DaysSinceItAllStarted; } ...

How to capture a string into variable in a recursive function?

I tried to print all the possible combination of members of several vectors. Why the function below doesn't return the string as I expected? #include <iostream> #include <vector> #include <fstream> #include <sstream> using namespace std; string EnumAll(const vector<vector<string> > &allVecs, size_t vecIndex, string strSoFar) {...

Private member function that takes a pointer to a private member in the same class

How can I do this? (The following code does NOT work, but I hope it explains the idea.) class MyClass { .... private: int ToBeCalled(int a, char* b); typedef (MyClass::*FuncSig)(int a, char* b); int Caller(FuncSig *func, char* some_string); } I want to call Caller in some way like: Caller(ToBeCalled, "stuff"...

Visual C++ saying void function needs to return a value

Visual C++ is saying my void function needs a return value I compiled this on my mac, and it worked perfectly, but now I am trying to compile this with Visual c++ (using windows 7) Heres the build log: Command Lines Creating temporary file "c:\Users\Jonathan\Documents\Visual Studio 2008\Projects\magicsquare\Debug\RSP000008229...

For C/C++, When is it beneficial not to use Object Oriented Programming?

I find myself always trying to fit everything into the OOP methodology, when I'm coding in C/C++. But I realize that I don't always have to force everything into this mold. What are some pros/cons for using the OOP methodology versus not? I'm more interested in the pros/cons of NOT using OOP (for example, are there optimization benefits ...

Help with segmentation fault in struct

Hello. I am having trouble debugging my code. I have a struct and a function to compute the time difference entered in HH:MM:SS format. My code is: const int hourConv = 3600; // used to get total hours from total seconds const int minConv = 60; struct MyTime { int hours, minutes, seconds; }; MyTime *determineElapsedTime(c...

how to change the switch-case statement to if-else statement

int number; cin>>number; switch (number) { case 1: cout<<"My Favourite Subject is"; break; case 2: cout<<"Fundamentals of Programming"; break; case 3: cout<<"Exit"; break; default: cout<<"Invalid Data"; } ...

query about a multithreading program

this might a simple query. when we are creating a thread we are passing the (void *)t as an argument to a function PrintHello.we are copying the value in the pointer threadid(typacasting it to long) in tid which is a long variable again.i am confused with the parameter passing. is this a pass by reference or pass by value.over all is t...

CUrl PUT with xml data

Hi I'm facing a problem with curl as I am unable to issue a PUT request with inline XML data, I'm not sure how its done but I hade a couple of goes on it with different techniques. First I tried using the CURLOPT_UPLOAD as its the default CURL option for PUT and tried to append the xml data manually: typedef map<string, string> hea...

Is there a better way of copying a string to a character array with things already in it...

messageBuffer[0] = 1; messageBuffer[1] = 0; for (int i = 2; i < (userName.size() + 2); i++) { messageBuffer[i] = userName[(i - 2)]; } userName is a string. I was just wondering if there is already a function that exists that I haven't found yet. I have tried looking on cpluscplus but nothing that I see. Thanks for all the help guys...

Sending Byte[][] inbetween C++ unmanaged dll and C# managed dll.

I have an unmanaged C++ dll that exports the following methods: ERASURE_API void encode(unsigned char ** inp, unsigned char ** outp, unsigned int *block_nums, size_t num_block_nums, size_t sz); ERASURE_API void decode(unsigned char ** inp, unsigned char ** outp, unsigned int * index, size_t sz); Size of inp and outp can be...

__FILE__ macro manipulation handling at compile time.

One of the issues I have had in porting some stuff from Solaris to Linux is that the Solaris compiler expands the macro __FILE__ during preprocessing to the file name (e.g. MyFile.cpp) whereas gcc on Linux expandeds out to the full path (e.g. /home/user/MyFile.cpp). This can be reasonably easily resolved using basename() but....if you're...

Weird memory leak

Hi I am having a memory leak problem and it is actually generating from the following structure array: TagStruct TagData [] = { { Tag_SecurityToken, string("x-abc-security-token"), string("ab-security-token") } , { Tag_XYZ, string("x-abc-xyz"), string("ab-xyz") }, { Tag_ChunkCount, string("x-abc-meta-chunk"), string("ab-me...

Compiler compiling external includes

Hello, I have a little problem in my project. I have build static library(e.g. test.lib) . Included it into my binary project linker and included #include "test.h" into stdafx.h. But when binary starts to build, C error occurs on CSomeObject test: "error C2146: syntax error : missing ';' before identifier 'test'". What could be wr...

file scope and static floats

Hello there. I've run into an interesting problem in an AI project of mine. I'm trying to format some debug text and something strange is happening. Here's a block of code: float ratio = 1.0f / TIME_MOD; TIME_MOD is a static float, declared in a separate file. This value is modified based off of user input in another class (I hav...

Server application have to make pings to N clients. Is there way to make it multithreaded?

I write server application (Windows Server 2003) making upto 1000 ping calls to clients and waiting for receive responses. As ping uses ICMP connection, I've found no way to define from which IP the server receives the responses. Currently I use blocking by Mutex but it practically removes all bonus of multhithreading. Is there another w...

Which VC++ runtime version do I choose - static or dynamic?

I'm developing a 64-bit in-proc VC++ ATL COM server that basically just redirects all calls to an out-proc COM server. So my COM server basically does nothing. Initially it used the C++ runtime in a DLL (/MD compiler switch). I've noticed that when I deploy it on a clean 64-bit Win2k3 regsvr32 fails with an error: LoadLibrary({fileName}...

Avoid std::bad_alloc. new should return a NULL pointer

I port a middle-sized application from C to C++. It doesn't deal anywhere with exceptions, and that shouldn't change. My (wrong!) understanding of C++ was (until I learned it the hard way yesterday) that the (default) new operator returns a NULL pointer in case of an allocation problem. However, that was only true until 1993 (or so). No...

How do I start to use multithread programming?

I am a beginner on Stack Overflow. I am working on a Unix platform in C/C++. Knowing basic programming in these regards how could I start with multithreading? Multithreading seems to be very interesting and I want to grow my knowledge in this regard. How could I get started with multithreading and what are the best techniques/books/ebo...

How to stop application from executing

I am working on a project to prevent applications from being launched from removable devices. Does anyone out there know how i can do this? Preferrably in C++ on the Windows platform. My aim is to prevent execution of the exe file even if the user double clicks it or even if he tries to launch it from the command line. ...