c++

Why does removing const give me linker errors?

I have a global variable: const std::string whiteSpaceBeforeLeadingCmntOption = "WhiteSpaceBeforeLeadingComment"; When I remove the const on this variable declaration, I get many occurrences of the following linker error: error LNK2005: "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > whiteSpac...

Problem in overriding malloc

Hi, I am trying to override malloc by doing this. #define malloc(X) my_malloc((X)) void* my_malloc(size_t size) { void *p = malloc(size); printf ("Allocated = %s, %s, %s, %x\n",__FILE__, __LINE__, __FUNCTION__, p); return p; } However, this is indefinitely calling my_malloc recursively (because of malloc call inside my_...

Voice Recognition in C++

I'm looking for a way to implement trainable voice recognition in C++. I've found the SAPI 5.3 SDK which looks promising, but the only tutorials that I can find are for TTS which is the opposite of what I want. Can anyone recommend a good tutorial that covers everything I would need to get SAPI up and running? Either that or is the...

const std::map<boost::tuples::tuple, std::string> ?

// BOOST Includes #include <boost/assign.hpp> // Boost::Assign #include <boost/assign/list_of.hpp> // Boost::Assign::List_Of #include <boost/assign/std/map.hpp> // Boost::Assign::Map_List_Of #include <boost/tuple/tuple.hpp> // Boost::Tuples // STD Includes #include <map> #include <vector> #include <string> // Using namespaces us...

Performance difference in for loop condition?

Hello all, I have a simple question that I am posing mostly for my curiousity. What are the differences between these two lines of code? (in C++) for(int i = 0; i < N, N > 0; i++) for(int i = 0; i < N && N > 0; i++) The selection of the conditions is completely arbitrary, I'm just interested in the differences between , and &&. I'm...

Exception slicing - is this due to generated copy constructor?

I've just fixed a very subtle bug in our code, caused by slicing of an exception, and I now want to make sure I understand exactly what was happening. Here's our base exception class, a derived class, and relevant functions: class Exception { public: // construction Exception(int code, const char* format="", ...); virtual ~Except...

Porting .NET C++ standalone to Mac

I need to give an estimate for porting a standalone program to a Mac from a .NET platform. I have all the source code which is in C++ and is both code I wrote and a modified version of GLUT/GLUI because the program uses OpenGL and GLUT/GLUI as a UI. I don't think the C++ code will be a problem or the OpenGL environment, please tell me ...

GCC C++ Linker errors: Undefined reference to 'vtable for XXX', Undefined reference to 'ClassName::ClassName()'

Hi, I'm setting up a C++ project, on Ubuntu x64, using Eclipse-CDT. I'm basically doing a hello world and linking to a commerical 3rd party library. I've included the header files, linked to their libraries, but I still get linker errors. Are there some possible problems here other than the obvious (e.g. I am 99% sure I'm linking to ...

How do I destruct data associated with an object after the object no longer exists?

I'm creating a class (say, C) that associates data (say, D) with an object (say, O). When O is destructed, O will notify C that it soon will no longer exist :( ... Later, when C feels it is the right time, C will let go of what belonged to O, namely D. If D can be any type of object, what's the best way for C to be able to execute "dele...

Using Boost::ref correctly..?

How can I get this to compile? The error is when I start using boost::ref(). I thought boost::ref is used to pass reference to C++ algorithm classes? list<Object> lst; lst.push_back(Object(1,2.0f)); lst.push_back(Object(3,4.3f)); struct between_1_and_10 { int d; void operator() (Object& value) { value.a +=...

Simple C++ Linked List

I have plenty of previous experience with linked lists in Java, but I seem to have confused myself with this simple attempt in C++. I am getting a segmentation fault at runtime, which from what I understand has to do with assigning a null pointer, but I am at a loss for a solution. Edit: Thank you all for the very helpful responses. The...

Convert struct to unsigned char *

How can I convert the following struct to unsigned char*? typedef struct { unsigned char uc1; unsigned char uc2; unsigned char uc3; unsigned char uc5; unsigned char uc6; } uchar_t; uchar_t *uc_ptr = new uchar; unsigned char * uc_ptr2 = static_cast<unsigned char*>(*uc_ptr); // invalid static cast at the previous line...

C++: Replacing part of string using iterators is not working.

Hello, I am writing a simple program, which is trying to find next palindrome number after given number. As for now, I am stuck at this point: string::iterator iter; // iterators for the string string::iterator riter; //testcases is a vector<string> with strings representing numbers. for (unsigned int i = 0; i < testcases.size() ; ...

How to format my own objects when using STL streams?

I want to output my own object to a STL stream but with customized formatting. I came up with something like this but since I never used locale and imbue before I have no idea if this makes sense and how to implement MyFacet and operator<<. So my questions are: does this make sense and how to implement MyFacet and operator<< ? The foll...

Flaws in algorithm and algorithm performance

char *stringmult(int n) { char *x = "hello "; for (int i=0; i<n; ++i) { char *y = new char[strlen(x) * 2]; strcpy(y,x); strcat(y,x); delete[] x; x=y; } return x; } I'm trying to figure out what the flaws of this segment is. For one, it deletes x and then tries to copy it's values over to y....

Function pointers casting in C++

Hi all, I have a void pointer returned by dlsym(), I want to call the function pointed by the void pointer. So I do a type conversion by casting: void *gptr = dlsym(some symbol..) ; typedef void (*fptr)(); fptr my_fptr = static_cast<fptr>(gptr) ; I hav also tried reinterpret_cast but no luck, although the C cast operator seems to work...

How to access Firefox's DOM (or HTML content) from outside firefox.

Hi guys! I have a question: My program will search FireFox windows opened by user. When a user open Firefox and enter any site, I want to search for a keyword in that page's HTML content. How can I access Firefox's Active Tab's DOM (or HTML content) from outside firefox using my C++ program. Is it possible? If so, can you give me som...

Is there open source software that uses STL extensively?

Is there open source software that uses STL extensively? ...

Automatic Java to C++ conversion

Has anyone tried automatic Java to C++ conversion for speed improvements? Is it a maintenance nightmare in the long run? Just read that is used to generate the HTML5 parsing engine in Gecko http://ejohn.org/blog/html-5-parsing/ ...

C++: instantiate class from name?

Hi, imagine I have a bunch of C++ related classes (all extending the same base class and providing the same constructor) that I declared in a common header file (which I include), and their implementations in some other files (which I compile and link statically as part of the build of my program). I would like to be able to instantia...