c++

C++: How to design a utility class?

Hi, The title says it all. But I don't know if I should go for static methods, just a header, a class, or something else? What would be best practice? But, I don't want to have an instance of a utility class. I want to add functions like: Uint32 MapRGB (int r, int g, int b); const char* CopyString(const char* char); // etc. You know:...

Is stack address shared by Heap addresses ??

I read On most operating systems, the addresses in memory starts from highest to lowest. So I am wondering if the heap, stack, and global memory all fall under the same ordering..? If I created... pointerType* pointer = new pointerType //creates memory address 0xffffff And then created a local varible on the stack localObject objec...

C++ JSON parser

Dear reader, I'm working on a twitter client which uses the twitter streaming json api. Twitter advices JSON as XML version is deprecated. I'm looking for a good JSON parser which can parse the json data below. I'm receiving this JSON which I want to be able to read/parse using a JSON parser. { "in_reply_to_status_id": null, "text": "...

C++ compiler error on template specialization

I would like to specialize a template method for a class C that is itself templated by an int parameter. How do I do this? template <int D=1> class C { static std::string foo () { stringstream ss; ss << D << endl; return ss.str();} }; template <class X> void test() { cout << "This is a test" << endl;} template <> template <...

C++ map to track when the end of map is reached

Currently I have a map that prints out the following map<string, map<int,int> > mapper; map<int,int>::iterator inner; map<string, map<int,int> >::iterator outer; for(outer = mapper.begin(); outer != mapper.end(); outer++){ cout<<outer->first<<": "; for(inner = outer->second.begin(); inner != outer->second.end(); inner++){ ...

IF Statement has strange behavior

I've developed a 'custom' cout, so that I can display text to console and also print it to a log file. This cout class is passed a different integer on initialization, with the integer representing the verbosity level of the message. If the current verbosity level is greater then or equal to the verbosity level of the message, the messag...

ptr_map inserting

Hello, I have some predefined type which inherits boost::noncopyable (so I have to store the pointer at these objects). I use a boost::ptr_map. As I know, the second argument in it is already a pointer. So, the code: ptr_map<string, boost::any> SomeMap; typedef %Some noncopyable class/signature% NewType; // Inserting now boost::any *te...

String method crashes program...

Alright so i have two identical string methods... string CreateCust() { string nameArray[] ={"Tom","Timo","Sally","Kelly","Bob","Thomas","Samantha","Maria"}; int d = rand() % (8 - 1 + 1) + 1; string e = nameArray[d]; return e; } string CreateFood() { string nameArray[] = {"spagetti", "ChickenSoup", "...

Extending the method pool of a concrete class which is derived by an interface

Hello, I had created an interface to abstract a part of the source for a later extension. But what if I want to extend the derived classes with some special methods? So I have the interface here: class virtualFoo { public: virtual ~virtualFoo() { } virtual void create() = 0; virtual void initialize() = 0; }; and one derived class ...

list or container O(1)-ish insertion/deletion performance, with array semantics

I'm looking for a collection that offers list semantics, but also allows array semantics. Say I have a list with the following items: apple orange carrot pear then my container array would: container[0] == apple container[1] == orangle container[2] == carrot Then say I delete the orange element: container[0] == apple cont...

Crash with new/delete, but not with malloc/free in C++ code

My developement environment is [Windows 7; visual studio 2010; x86]. I have a dll that was built for server 2003 long time back. When I use it in my project and follow new/delete sequence to use a class, application crashes during delete call. I verified the same even without any other call between new and delete. When I replace new/del...

CPU Process time using GetProcessTimes and FileTimeToSystemTime do not work in 64 bit win

So I am trying to measure CPU time. It works great on Win 32, but on 64 bit it says error LNK2019: unresolved external symbol __imp_GetProcessTimes referenced in function "unsigned int __cdecl getWINTime(void)" (?getWIN32Time@@YAIXZ) it has similar error for FileTimeToSystemTime error LNK2019: unresolved external symbol __imp_FileTi...

Getting a directory name from a filename

I have a filename (C:\folder\foo.txt) and I need to retrieve the folder name (C:\folder) in unmanaged C++. In C# I would do something like this: string folder = new FileInfo("C:\folder\foo.txt").DirectoryName; Is there a function that can be used in unmanaged C++ to extract the path from the filename? ...

What is the fastest design to download and convert a large binary file?

I have a 1GB binary file on another system. Requirement: ftp/download and convert binary to CSV on main system. The converted file will be magnitudes larger ~ 8GB What is the most common way of doing something similar to this? Should this be a two step independent process, download - then convert? Should I download small chunks at...

does sfinae instantiates a function body?

I want to detect existence of a specific member function for a class, using the usual SFINAE trick. template<typename T> struct has_alloc { template<typename U,U x> struct dummy; template<typename U> static char test(dummy<void* (U::*)(std::size_t),&U::allocate>*); template<typename U> static char (&test(...))[...

C++ Union, Struct, Member type

If I have a class: class Odp { int i; int b; union { long f; struct { WCHAR* pwszFoo; HRESULT hr; }; }; } Union means that, of all values listed, it can only take on one of those values at a time? How does that work in terms of accessing these varia...

Building xerces using -icu

Hi, is any body aware of building xerces using icu library , when i am building it giving all icu related option on MacOS its never going for icu option ( it finally says ICU option can not be enabled in config.log ). ./configure --prefix=/tmp/xer --enable-msgloader-icu --disable-shared --disable-network --enable-static --disable-t...

Can I reconstruct C++ source code from debug binaries?

I have a C++ application compiled in debug (using MinGW and Qt) but I've lost some major changes because someone in my team forgot to commit his changes in the source control manager and overwrote the source code with other changes. When I run the program in debug (in Qt Creator) I can set a break point in main and then see the source c...

sizeof(Structure) Confusion

In the following piece of code, #include<stdio.h> typedef struct { int bit1:1; int bit3:4; int bit4:4; } node; int main(){ node n,n1,n2,ff[10]; printf("%d\n",sizeof(node)); return 0; } How do I predict the size of the structure? ...

Determine which Explorer.exe on Task List is really the shell?

HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "Shell" returns the shell name, usually Explorer.exe. However, it does not contain the path, or identify a particular executable file. Enumerating the Task List locates the task Explorer.exe. But what if the user had ran another, unrelated task called Explorer...