c++

How can I force symbol a symbol reference in c++ (programmatically)

Hi, I'm trying to plug tcmalloc into a suite of software that we currently use at work. The software comprises of a lot of dll's. They all refer to a shared header file, so I can pragma link the library. However as none of the code refers to the symbol __tcmalloc the optimizer strips the dll. Now I don't want to have to edit 200 projec...

c++: ifstream open problem with passing a string for text file name

hi guys, i'm trying to pass a string from main to another function. this string is a name of text file that needs to be oepened. as far as i can see, i am passing the string alright, but when i try to use ifstream.open(textFileName), it doesn't quite work. but when i manually hardcode it as ifstream.open("foo.txt"), it works just fine. i...

initializing a const multidimensional array in c++

I'm currently working through some exercises in a c++ book, which uses text based games as its teaching tool. The exercise I am stuck on involves getting the pc to select a word from a const array of words (strings), mixing the letters up and asking the player to guess the word. This was easy, but as a follow on the book asks to add the ...

Why is this boost::variant example not working?

I am getting to know boost::variant. I think this example should work. #include <boost/fusion/sequence.hpp> #include <boost/fusion/include/sequence.hpp> #include <boost/variant/variant.hpp> #include <string> #include <vector> #include <iostream> #include <boost/variant/get.hpp> boost::variant< bool,long,double,std::string, std::vector<...

Qt in a professional setting

While I have played with parts of Qt in the past I am thinking of putting some real effort into learning it but also wondering what the potential monetary payback might be down the road. So I have some general questions about Qt's future. What is Qt's place in the job market? Are there many, or do you sense a growing number of install...

Using valid STATIC member function of class that can't be installed

Hello, I have following piece of code: It compiles without problems under gcc-3.4, gcc-4.3, intel compiler, but fails under MSVC9. MSVC tells "use of undefined type c_traits<C>, while compiling class template member function void foo<C>::go(void) with C=short. The point it the compiler tries to install unused member function of unuse...

What are the differences between using array offsets vs pointer incrementation?

Given 2 functions, which should be faster, if there is any difference at all? Assume that the input data is very large void iterate1(const char* pIn, int Size) { for ( int offset = 0; offset < Size; ++offset ) { doSomething( pIn[offset] ); } } vs void iterate2(const char* pIn, int Size) { const char* pEnd = pIn+Siz...

Why is my merge sort not working?

It compiles fine, but when it runs, it adds random high numbers to the list, as well as duplicates of existing numbers. I've had a couple of people look over this, and none of them can figure it out. void mergeSort(int list[], int length) { recMergeSort(list, 0, length - 1); } void recMergeSort(int list[], int first, int last) { ...

Compiler warnings with MySQL++ with release configuration.

For some reason I get some warnings about "non dll-interface class" when building with a release configuration, but not debug. I've compared the release and debug configurations, and my ones with the MySQL++ example ones, however I cant see which setting is causing these warnings. 1>c:\sql\mysql 5.0\mysql++-3.0.9\lib\qparms.h(49) : war...

C++ referring to an object being constructed.

In C++ I have a reference to an object that wants to point back to its owner, but I can't set the pointer during the containing class' construction because its not done constructing. So I'm trying to do something like this: class A { public: A() : b(this) {} private: B b; }; class B { public: B(A* _a) : a(_a) ...

Conversion problem

I'm using gcc 4.3.2. I have the following code (simplified): #include <cstdlib> template<int SIZE> class Buffer { public: explicit Buffer(const char *p = NULL) {} explicit Buffer(const Buffer &other); const char *c_str() const { return m_buffer; } private: char m_buffer[SIZE]; }; typedef Buffer<10> A; typedef Buffer...

Is boost::object_pool synchronized?

Is boost::object_pool synchronized? ...

Why does initialization of a template type require a repeat of the type of the variable?

Suppose I have an object that has a member variable that is of some template type. So, in the declaration of the class, there would be something like this: // This is just the declaration of bar which is a member of some class. templatizedType<Foo> bar; Now, when I want to initialize bar why do I have to do // This is the initializa...

Turning text into executable statements

This is a question out of curiousity for java or c++, I wanted to ask if it is possible to turn any text input into some executable statements? For example say I have a text file with info like: "class: Abc, Param: 32" Now say in C++ or Java I want to read that file and do something like: new Abc(32); How would I do that? Its easy...

Template specialization problem

Hi, I'm trying really hard to made this work, but I'm having no luck. I'm sure there is a work around, but I haven't run across it yet. Alright, let's see if I can describe the problem and the needs simply enough: I have a RGB template class that can take typenames as one of its template parameters. It takes the typename and sends it...

Multi Including a .h File

Hi, In an .h file, I am declaring a global variable as: #pragma data_seg(".shared") #ifndef DEF_VARX #define DEF_VARX int VARX=0; #endif /*DEF_VARX*/ #pragma data_seg() #pragma comment(linker, "/SECTION:.shared,RWS") However if I include this file in multiple cpp files, when I try to compile, I get " error LNK2005: "int VARX" (?VARX@...

Translating Program

I am beginning to write a translator program which will translate a string of text found on a file using parallel arrays. The language to translate is pig Latin. I created a text file to use as a pig latin to English dictionary. I didn't want to use any two dimension arrays; I want to keep the arrays in one dimension. Basically I want to...

C++/Qt download file in sync

Hi I want to achieve to download a file in a separate thread and store that file, but I was not able to find an appropriate way to achieve this without evil delay (quite frequent download of small files, so signal+slots are too slow). What I want to achieve: (Pseudo Code) request file; wait for download finishing, timeout or error; save...

Visual Studio unmanaged C++ code formatter

When I type this line of code: QString newPath = QFileDialog::GetOpenFileName(this, tr("Open Image"), path, tr("Image files (%1)").arg(formats.join(" "))); I typically format it like this: QString newPath = QFileDialog::GetOpenFileName(this, tr("Open Image"), ...

DLL Shared Data Section Does Not Exist Error

Hi, I try to declare a shared data segment in a DLL. I declare the area with: #pragma data_seg(".shared") int varx=0; #pragma data_seg() __declspec(allocate(".shared")) // I found this declspec suggestion in another forum #pragma comment (linker,"/section:.shared,RWS") Also I add SECTIONS .shared READ WRITE SHARED into the...