c++

C++ remove node binary search tree

...

Updating global variables from a single worker thread: Do I need mutexes?

It seems that this question gets asked frequently, but I am not coming to any definitive conclusion. I need a little help on determining whether or not I should (or must!) implement locking code when accessing/modifying global variables when I have: global variables defined at file scope a single "worker" thread reading/writing to glob...

How to avoid results change when moving from 32 bit to 64 bit system?

Lately I run my C++ program that was built and tuned in 32 bit system on a 64 bit system and I notice there are some bad performance changes. In my code, I used a lot float point variables. Now I suspect this may be the reason for the bad changes. Is there anyway to avoid such performance changes when moving code from 32bit to 64 bit sys...

templated class with templated constructor (of other type)

Is it possible to have a templated class and also templating the constructor with some other type? something like this: template<typename T1> class Foo{ template<typename T2> Foo(T1 aBar, T2 dummyArgument){ bar = aBar; bytesOfT2 = sizeof(T2); }; int bytesOfT2; T1 bar; }; is this possible? and if s...

"Cannot open include file: 'fstream.h'" error in Visual Studio 2008 Express Edition

When compiling this code I get: fatal error C1083: Cannot open include file: 'fstream.h': No such file or directory Why? Code: #include <windows.h> // use as needed for your system #include <gl/Gl.h> #include <gl/glut.h> #include <iostream> #include <fstream.h> //**************Global Data char ifileName[30],oFileName[30]; fstrea...

C++ boost how to get a number of members in enum?

is there anything in the boost which could help to get a number of members in enumeration? e.g. to return 3 for the following code: enum SomeEnum { One, Two, Three } ...

fatal errors LNK2001 & LNK1120 in VS Express Edition 2008

The following code compiles on VS Express Edition 2008, yet I get the following errors when trying to debug/release: 1>Linking... 1>MSVCRT.lib(crtexew.obj) : error LNK2001: unresolved external symbol _WinMain@16 1>E:\Documents and Settings\Administrator\Desktop\Proyecto 2 gràficas\testing\Release\testing.exe : fatal error LNK1120: 1 unr...

Trying to sort an array.

I'm trying to sort an array least to greatest and i am really lost.... Here is what i have so far: int temp, temp2; for (int x = 0; x < array_size; x++) { temp=a[x]; for (int i = 0; i < array_size; i++) { if (a[i] < temp) { temp2=a[i]; ...

Stopping or Blocking Inheritance in C++

I would to block child classes from overriding a base method and have the child classes override a new method in a parental class. In other words, a child class of the base class blocks the base class methods and delegates to a new method that further child classes must override. I still want the base class method to be available. Her...

Boost 1.44.0 + VS2010 Private member error

I have a class declaration in Utils.h: class Utils { private: static boost::mutex outputMutex; }; In the cpp file: boost::mutex Utils::outputMutex = boost::mutex(); I get: Error 1 error C2248: 'boost::mutex::mutex' : cannot access private member declared in class 'boost::mutex' If we look inside boost/thread/win32/...

something like a using declaration for enums?

Basically this is what I'd like to do: struct A { enum E { X, Y, Z }; }; template <class T> struct B { using T::E; }; // basically "import" the A::E enum into B. std::cout << B<A>::X << std::endl; The reason why is that I want to basically inject the implementation details into my template class. At the same time...

pointer to std::vector of arbitrary type (or any other templated class)

Hi! let's say i want to have a member variable for a pointer to std::vector but i do not want to specify what type of variable it stores. I want to access only those functions that are independant of it's actual generic type. is this possible with c++? something like this: class Foo{ public: void setVec(std::vector* someVec){ ...

Problems with binary search function.

Having trouble with the binary_search function listed at the top. not sure where to go with it. I'm not very familiar with binary searching. #include <iostream> #include <cstdlib> #include <fstream> using namespace std; void get_input(ifstream& fin, int a[], int size, int & array_size); void binary_search (int a[], int & array_size) ...

STL queue push behavior

I come across a behavior in STL queue push which I don't quite understand. Basically, I have two struct structA{ string a; } structB{ char b[256]; } structA st1; structB st2; ...assign a 256 characters string to both st1 and st2... queue<structA> q1; queue<structB> q2; for(int i=0 ; i< 10000; i++){ q1.push(st1); } for(int i...

C++: Initialization of inherited field

Hello, I've a question about initialization of inherited members in constructor of derived class. Example code: class A { public: int m_int; }; class B: public A { public: B():m_int(0){} }; This code gives me the following output: In constructor 'B::B()': Line 10: error: class 'B' does not have any field na...

Multi threaded client server

Hi I am working on an assignment writing multi threaded client server. So far I have done is open a socket in a port and forked two thread for listening and writing to client. But I need to connect two type of clients to the server and service them differently. My question is what would be my best approach? I am handling connection in a...

Model View Controller Design pattern Code Example

I was studying the Model-View-Controller design pattern and i understand the concept behind the pattern theorotically, but I wanted to get a peek at how one would actually put it to practice. Wikipedia mentions Wt - Web toolkit, CppCMS and some other standard implementations which use the pattern however I have not been familiar with the...

got "cannot appear in a constant-expression" when using template

Hi , template < int > class CAT {}; int main() { int i=10; CAT<(const int)i> cat; return 0; //here I got error: ‘i’ cannot appear in a constant-expression } even int i=10; const int j=i; CAT<j> cat; //this still can not work but I have convert i to const int ,why compiler...

How to remove unwanted functions from interface.

I have an interface class MyFunction. There are three functions in this class with the following signatures: virtual bool Eval(int& iReturnVal, size_t szArgumentCount, list<Param> lParameterList) = 0; virtual bool Eval(double& dReturnVal, size_t szArgumentCount, list<Param> lParameterList) = 0; virtual bool Eval(char*& zReturnVal, size_...

how can i paint row with different color in QTreeWidget (Qt)

i have in my application that when i click on row i have the default blue row marked but beside this blue color i what to paint the row in different color via function not depending on user clicked signal , in sort i need a function that i will pass the row index and it will paint the row in x color. ...