c++

Getting multiple definition error

Hey, I'm trying to compile some c++ files. I'm getting the following types of errors at the linking phase (the compiling is working) - Main.o: In function operator<<(std::basic_ostream<char, std::char_traits<char> >&, Set const&)': /usr/include/c++/4.3/new:105: multiple definition of operator<<(std::basic_ostream< char, std::char_tr...

Modifying contents of vector in BOOST_FOREACH

This is a question that goes to how BOOST_FOREACH checks it's loop termination cout << "Testing BOOST_FOREACH" << endl; vector<int> numbers; numbers.reserve(8); numbers.push_back(1); numbers.push_back(2); numbers.push_back(3); cout << "capacity = " << numbers.capacity() << endl; BOOST_FOREACH(int elem, numbers) { cout << elem << end...

Does using __declspec(novtable) on abstract base classes affect RTTI in any way?

Or, are there any other known negative affects of employing __declspec(novtable)? I can't seem to find references to any issues. ...

C/C++: any way to get reflective enums?

I've encountered this situation so many times... enum Fruit { Apple, Banana, Pear, Tomato }; Now I have Fruit f; // banana and I want to go from f to the string "Banana"; or I have string s = "Banana" and from that I want to go to Banana // enum value or int. So far I've been doing this.. Assuming the enum is in Fruit.h: /...

Why no compiler enforcement in const_iterator

Consider the following code : #include <vector> #include <iostream> class a { public: int i; void fun() { i = 999; } void fun() const { std::cout << "const fun" << std::endl; } }; const a* ha() { return new a(); } int main() { std::vector<a *> v; v.push_back(new a()); // cannot convert from 'const a *' to...

Algorithm - How to delete duplicate elements in a list efficiently?

There is a list L. It contains elements of arbitrary type each. How to delete all duplicate elements in such list efficiently? ORDER must be preserved Just an algorithm is required, so no import any external library is allowed. Related questions In Python, what is the fastest algorithm for removing duplicates from a list so that all ...

Speeding up self-similarity in an image

I'm writing a program that will generate images. One measurement that I want is the amount of "self-similarity" in the image. I wrote the following code that looks for the countBest-th best matches for each sizeWindow * sizeWindow window in the picture: double Pattern::selfSimilar(int sizeWindow, int countBest) { std::vector<int> ...

STL container's read-only operations

Need advice here: which of the STL container's operations are considered read-only? Take vector<int> as example, would it be safe to say that any operation that does not alter the underlying int data is read-only? I am writing a multi-threaded program, but not too sure if it is thread-safe to pass container by reference/pointer. Between...

Making map::find operation case insensitive

Does the map::find method support case insensitive search? I have a map as follows map<string,vector<string> > directory; and want the below search to ignore case. directory.find(search_string); ...

How can a C++ base class determine at runtime if a method has been overridden?

The sample method below is intended to detect whether or not it has been overridden in a derived class. The error I get from MSVC implies that it is simply wrong to try to get the function pointer to a "bound" member, but I see no logical reason why this should be a problem (after all, it will be in this->vtable). Is there any non-hacky ...

Why does this pointer to C++ function code generate a compile error?

Can anyone solve this? I can’t seem to find the solution anywhere, but I see no logical reason why the line below (with the comment showing the compile error) should be a problem. Note: This question is a derivative of How can a C++ base class determine at runtime if a method has been overridden? class MyClass { typedef void (...

How to export all functions inside PHP extension?

I opened php_sqlite.dll & php_sockets.dll using Depends.exe. I saw only 1 function in both: get_module How can I export all functions in extension to dll files when compiling the .dll? AFAIK, ZEND_FUNCTION is used to declare functions in the modules. Please kindly advise. Thank you very much! ...

Common Practice for Template Function Defination - Mix with Function Declaration?

Most of the time, I "avoid" to have the following style in my single header file. class a { void fun(); }; void a::fun() { } In order to avoid the following error. I try to separate class definition in cpp file and class declaration in h file. For example, the below is the wrong example : main.cpp #include "b.h" #include "a.h...

I can not get access to pointer to member. Why?

Consider the following code: template<class T, class F> struct X {}; template<class T, class F, T F::* m> struct Y {}; struct Foo { int member; typedef X<int, Foo> x_type; // works well typedef Y<int, Foo, &Foo::member> y_type; // ERROR }; typedef Y<int, Foo, &Foo::member> y_type2; // OK Why does ...

Decompression from unicode to 7bit ascii

hello all can anyone help me in finding the code for decompress the unicode to 7bit ascii thanx ...

Please show me a situtation which shows `need` for Delegates (or) function pointers.

Hello, I'm going take a class on "Delegates and Callbacks" to students who are learning level programmers. They have basic c/c++ & c# background. Instead of directly showing how to use them. I want to show "Why Function Pointers?" first. I want to start with an example situation and ask them "How will you do this"? and make them realize...

Call Back Functions

Someone suggested to me to use Call Back Functions to implement a timer to run in the background while my Server application reads input from clients. I tried looking at explanations online, but was hoping if someone could give me a simpler analogy. Thanks. ...

Race between virtual function and pthread_create

When I try to create a class instance with a virtual method and pass it to pthread_create, I get a race condition, causing the caller to sometimes call the base method instead of the derived method like it should. After googling pthread vtable race, I found out this is fairly well-known behavior. My question is, what's a good way to ge...

C# Design guidance for generic image processing library.

Hi all, In any image processing library there is always the issue of having to provide an implementation of every single algorithm for every single image format (color space, channels, bit depth, mem layout, etc). One very elegant solution to the problem is Boost GIL. Through the power of C++, and a great design, all of these issues are...

Supress console when calling "system" in c++

I'm using the system command in C++ to call some external program, and whenever I use it, a console window opens and closes after the command finishes. How can I avoid the opening of a console window? I would be happy if the solution could be platform-independent. I would also like for my program to wait until the command is finished....