c++

Adding const-ness after the fact in C++

Possible Duplicate: Is there some ninja trick to make a variable constant after its declaration? Consider the following minimal example: void MutateData(std::string&); int main() { std::string data = "something that makes sense to humans."; ::MutateData(data); // Mutates 'data' -- e.g., only changes the order of the cha...

C++, JsonCpp, libcurl and UTF-8 woes

I had some problems making libcurl work with C++ JsonCpp library and, after a lot of research, I came up with this code: int post(const string& call, const string& key, const string& value) { // (...) char* char_data=NULL; struct curl_slist *headers=NULL; headers = curl_slist_append(headers, "Content-Type: application/json; c...

C++ Unicode Bullet Point

Hi stackoverflow! I am trying to insert the Unicode character U+2022 (bullet •) in my C++ application. I can't figure out how to convert that U+2022 to a char/string for use in std::string constructor... char bullet = char(0x2022); mPassword.SetText( std::string(mText.length(), bullet) ); This one doesn't work. Hope you can help !!...

What does `invalid initialization of non-const reference` mean?

When compiling this code I get the following error: In function 'int main()': Line 11: error: invalid initialization of non-const reference of type 'Main&' from a temporary of type 'Main' template <class T> struct Main { static Main tempFunction(){ return Main(); } }; int main() { Main<int> &mainReference = Main<int>...

multiple definition

My code had an error about not defining the operator<. I corrected the operator< problem in my code by overloading it. When I compile it, there was no error there but it has lots of errors about multidefinition. My code is: int Vector3D::operator < (const Vector 3D &vector) const { if(x<vector.x) return 1; else return 0; } Her...

Generating Code from a Source File Using Doxygen

I'm using doxygen to generate HTML documentation. I have a C++ source file that contains only global functions. All of the global functions are document, and the documentation is properly generated. For all of the headers in the project there is a link to “see the code that this documentation was generated by.” (as a link to the HTMLized...

How many bits to ignore when checking for NULL?

The following crashes with a seg-V: // my code int* ipt; int bool set = false; void Set(int* i) { ASSERT(i); ipt = i; set = true; } int Get() { return set ? *ipt : 0; } // code that I don't control. struct S { int I, int J; } int main() { S* ip = NULL; // code that, as a bug, forgets to set ip... Set(&ip->J); // gobs o...

Lists of member pointer functions

Say I have a class: class A { public: void doSomething(); } Where doSomething does something that explicitly relies on the internal state of the instance of A. Now, I have a situation where I have a bunch of things of type A laying around, but I only want to call doSomething from a strict subset of them, so I want to stick them on ...

How to resize an image in a QTextEdit?

How to click on the image, hold from a corner of it, and resize the image in the QTextEdit? Or at least how to get an image under cursor/that is selected in order to change width and hight? ...

Access C++ shared library from Java: JNI, JNA, CNI, or SWIG?

Which of the following (or other) method would you recommend for accessing a C++ shared library from Java and why? JNI: I hear this has a number of pitfalls and is quite the undertaking? SWIG: Apparently this makes using JNI easier, but I've heard it has some problems too? JNA: I could write a C interface and then use JNA with it i...

Desctuction of object is causing the crash of the program

Here is a snippet of a considerably big C++ program: map<int, int>::iterator class_it = docsCountPerClass.begin(); for( ;class_it != docsCountPerClass.end(); class_it++) { cout << "classid: " << class_it->first << '\n'; vector<term_importance> ti; ti.reserve(termids.size()); vector<int>::iterator term_it = termids.begin...

linux background card swipe reader

I currently have a USB card swipe attached to an embedded linux machine and from what I can tell and from what I have researched it acts as a keyboard, and inputs all the data as if I were typing. Now I have a perl script that takes all this data and saves it to a file. The only problem is, it only knows to take the data when the perl sc...

Machine Learning Library?

Which libraries do you use for machine learning for C/C++, Python, Java? ...

Way to check if type is an enum.

How to check (without Boost or other nonstandard lib) if type passed to template is an enum type? Thanks. ...

C ++ using dcmtk library

I want to use dcmtk library in my project in C++. How should i add these libraries to the project? I tried : #include "dcmtk/ofstd/ofstdinc.h" and adding every file to 'Header file', but there are to many libraries to add. How can i add these shorter? . How can i convert it to .dll library for use it in C# project? ...

typeid operator in C++

I have the following code int main() { cout << "Please enter your name..." << endl; cin >> name; cout << "Data type = " << typeid(name).name() << endl; cin.get(); return 0; } According to the various textbooks and pieces of documentation I've read about the typeid operator, I should expect to read "Data type = str...

Why do I not see the "Application Error" dialog box?

I was interested in learning more about mixing runtimes between exes and dlls. On a WinXP machine, I created a dll build against the release runtime (/MD) and an exe that calls a function in the dll that is built debug (/MDd). The function in the dll allocates memory to the heap and the exe deletes it. I expected this to crash, howeve...

gdb error message: DW_OP_reg, DW_OP_piece, and DW_OP_bit_piece

I'm debugging somebody else's Qt program and ran into the following error message which I don't understand: DWARF-2 expression error: DW_OP_reg operations must be used either alone or in conjuction with DW_OP_piece or DW_OP_bit_piece. I'm not sure what that means and Google isn't of much help. Here's the context - sLocation is a QStr...

Crossplatform building Boost with SCons

I tried hard but couldn't find an example of using SCons (or any build system for that matter) to build on both gcc and mvc++ with boost libraries. Currently my SConstruct looks like env = Environment() env.Object(Glob('*.cpp')) env.Program(target='test', source=Glob('*.o'), LIBS=['boost_filesystem-mt', 'boost_system-mt', 'boost_progr...

C++ encode string to Unicode - ICU library

Hi, I need to convert a bunch of bytes in ISO-2022-JP and ISO-2022-JP-2 (and other variations of ISO-2022) into Unicode. I am trying to use ICU (link text), but the following code doesn't work. std::string input = "\x1B\x28\x4A" "ABC\xA6\xA7"; //the first 3 chars are escape sequence to use JIS_X201 character set in GL/GR UErrorCode...