c++

Add remote library in netbeans c++ application

I am writing a c++ application that uses mysql, and I am having a problem with including in my project. I am using netbeans with remote development and I am wondering how do I add the mysql folder (/usr/local/mysql/include/mysql/) into my include path over remote development. I notice that netbeans copies across all standard libraries...

Cyclical Linked List Algorithm

I have been asked recently in a job interview to develop an algorithm that can determine whether a linked list is cyclical. As it's a linked list, we don't know its size. It's a doubly-linked list with each node having 'next' and 'previous' pointers. A node can be connected to any other node or it can be connected to itself. The only s...

can not count array elements after passing as argument

I am having issues counting the array elements after passing it into an arguement void GXDX::LoadMesh(GXVector vertices[], UINT indices[] = NULL) { D3D10_BUFFER_DESC bufferDesc; UINT numVerts = sizeof(vertices)/sizeof(GXVector); bufferDesc.Usage = D3D10_USAGE_DEFAULT; bufferDesc.ByteWidth = sizeof(GXVector) * numVerts;...

Stupid question about `delete` and pointers

Say we have a piece of code: //... class A //... A* myA = new A(); A* myPointerToMyA = myA; delete myA; delete myPointerToMyA; // this is wrong, no? //... The last line does the exact same thing as the one above it, correct? So I would now be deleteing an invalid/NULL pointer? I understand this may be a stupid question, but still, I ...

OpenMP, C++ and Iterators.

To loop over elements of a container, I would typically use an iterator, like so: container<type> myContainer; // fill up the container container<type>::iterator it; for(it=myContainer.begin(); it!=myContainer.end(); ++it) { //do stuff to the elements of the container } Now, if I want to parallelize the loop using OpenMP, I might t...

Why is the code printing the last std::cout??

using namespace std; template<typename T> int f(vector<T> &v){ return v.size(); } template<typename T> class B{ public: int size(){ return v.size(); }; private: vector<T> v; }; int main(int argc, char** argv) { B<string> b; vector<string> v; for(int i=0; i<f<string>(v)-1; i++) std::cout <...

Why doesn't auto_ptr<T> have operator!() defined?

The Title pretty much sums up my question. Why can't the following be done to check for a null pointer? auto_ptr<char> p( some_expression ); // ... if ( !p ) // error This must be done instead: if ( !p.get() ) // OK Why doesn't auto_ptr<T> simply have operator!() defined? ...

Processing command line argument

Hi, I've been working with OpenCV, and some of the example code I've seen uses the following to read in a filename. I understand that argc is the number of command line arguments that were passes, and argv is a vector of argument strings, but can someone clarify what each part of the following line does? I've tried searching this but ha...

Unresolved external symbols in compiling 32 bit application in Windows 64

So I am trying to compile legacy app from 32 bit to 64 bit.. I re-compiled all of the libs it used and made it look into WIN SDK6.0A x64 bit for libs.. I am using: Visual Studio Professional Edition 2008 Visual C++ dotNet Framework 3.5 SP1 Windows Server 2008R2 Windows SDK is 6.0A Everythings finally coming up but I am getting these...

boost program_options multiple values problem

So I'm working off one of the examples for Boost program_options library, and I wanted to try setting a default value for one of the multiple-values/ vector-values, but it doesn't seem to work. As I think is suggested here to work. What I've modified is on about line 40: po::options_description config("Configuration"); config.a...

Why isn't the dropdown arrow drawn for an CMFCMenuButton?

I ran into this issue when trying to add a CMFCMenuButton to an existing MFC application. It worked properly, and even resized the button to accommodate the dropdown arrow. But it didn't draw the dropdown arrow, and when I hovered over the button, I saw the following debug output: > Can't load bitmap: 42b8.GetLastError() = 716 > CMenu...

Qt: How do I set the QComboBox width to fit the largest item?

Hi, I have a QComboBox that I fill with QStrings using: comboBox->addItem(someString); When I start my GUI application the width of the comboBox is always 70, even if the smallest item is much larger. How can I dynamically set the width of a QComboBox, for instance, to the largest QString within the comboBox? Thanks! Edit: After so...

Compare 2 elements of two arrays in C++

I have two arrays each array has some values for instance: int a[] = {1, 2, 3, 4}; int b[] = {0, 1, 5, 6}; now I need to compare the elements of the array (a) with elements in array (b).. if is there any match the program should return an error or print "error there is a duplicate value" etc.. in the above situation, it should retur...

C++ template instantiation restrictions

I have a method foo in class C which either calls foo_1 or foo_2. This method foo() has to be defined in C because foo() is pure virtual in BaseClass and I actually have to make objects of type C. Code below: template <class T> class C:public BaseClass{ void foo() { if (something()) foo_1; else foo_2; } void foo_1() { ...

run quickfix engine

Hello, I'm trying to get started with c++ quickfix engine. I downloaded the project (VS2010 version). The documentation is rather poor, so my understanding is that the project quickfix_vs10 is the actual library and the other projects that I would need to run are example_ordermatch_vs10, the executor_cpp_vs10 and the example_tradeclient...

how to use an edit control in MFC?

i want to make an edit control box in which user can enter some value. so i drag an edit control to my dialog. add a variable "value" of type CString to this edit control. then i add an event handler of message type EN_CHANGE to this edit control. what should i do next? ...

Segmentation fault -- How!

int Sequence::scoreDegeneracy() { cout << "Score Degeneracy" << name << seqLen << endl; int f = 0; if (degenComputed == false) { char _2foldTest = '*'; char _4foldTest = '*'; int aaseqLen = seqLen/3; int i = 0; for (i; i < aaseqLen; i++) { _4foldTest = is4FoldD...

Static check const char* contains spaces

Is there a way to check (assert) at compile time wether a const char* contains spaces or not? Something like: const char* cstr1 = "ok"; const char* cstr2 = "very bad"; check( cstr1 ); //OK check( cstr2 ); //Fail to compile The type is the same, but it may be possible to define some tricky template metaprogramming tecnique to do it. ...

Why are heaps in c++ implemented as algorithms instead of containers?

I was wondering why the heap concept is implemented as algorithms (make_heap, pop_heap, push_heap, sort_heap) instead of a container. I am especially interested is some one's solution can also explain why set and map are containers instead of similar collections of algorithms (make_set add_set rm_set etc). ...

Case insensitive std::string.find()

I am using std::string's find() method to test if a string is a substring of another. Now I need case insensitive version of the same thing. For string comparison I can always turn to stricmp() but there doesn't seem to be a stristr(). I have found various answers and most suggest using Boost which is not an option in my case. Addition...