c++

C++ double operator+

Possible Duplicates: Incorrect floating point math? Float compile-time calculation not happening? Strange stuff going on today, I'm about to lose it... #include <iomanip> #include <iostream> using namespace std; int main() { cout << setprecision(14); cout << (1/9+1/9+4/9) << endl; } This code outputs 0 on MSVC 9....

g++ __FUNCTION__ replace time

Hi, can anyone tell when g++ replaces the __FUNCTION__ 'macro' with the string containing the function name? It seems it can replace it not until it has check the syntactical correctness of the source code, i.e. the following will not work #include <whatsneeded> #define DBG_WHEREAMI __FUNCTION__ __FILE__ __LINE__ int main(int argc, ch...

Rvalues vs temporaries............

Somebody generalized the statement "Temporaries are rvalues". I said "no" and gave him the following example double k=3; double& foo() { return k; } int main() { foo()=3; //foo() creates a temporary which is an lvalue } Is my interpretation correct? ...

QThread blocking main application

I have a simple form UI that has a slot for a button, starting a thread: void MainWindow::LoadImage() { aThread->run(); } And the run() method looks like this: void CameraThread::run() { qDebug("Staring Thread"); while(1) { qDebug("ping"); QThread::sleep(1); } } When I click the button that calls...

C++ member function masking external function - how to call external function?

In a Qt application, I'm trying to call the networking function connect() (which is from sys/socket.h). The call's being made from a QObject object, which has its own connect() member function. The QObject's connect() method is preventing me from calling the networking connect() function. Any way to use the networking connect()? ...

How to get length of std::stringstream without copying

Hi, How can I get the length in bytes of a stringstream. stringstream.str().length(); would copy the contents into std::string. I don't want to make a copy. Or if anyone can suggest another iostream that works in memory, can be passed off for writing to another ostream, and can get the size of it easily I'll use that. ...

question about inline keyword

Possible Duplicate: Usefulness of the inline feature why is used inline keyword in c++? ...

Linking Statically with glibc and libstdc++

Hey all, I'm writing a cross-platform application which is not GNU GPL compatible. The major problem I'm currently facing is that the application is linked dynamically with glibc and libstdc++, and almost every new major update to the libraries are not backwards compatible. Hence, random crashes are seen in my application. As a workaro...

Incomplete type as function parameter?

I have that template class that uses a policy for it's output and another template argument to determine the type for it's data members. Furthermore the constructor takes pointers to base classes which are stored in private pointers. Functions of this objects shall take a this pointer to the template class to give them access to the data...

Deriving a pointer type to the non-pointer class member

In book named "Using C++" by Rob McGregor there is following example of using pointer-to-member operator class mycls { public: int member; int *ptr; }; void main() { mycls MyClass; // Derive a pointer type to the non-pointer class member int mycls::*member = &mycls::member; MyClass.ptr = new int; mycls* pM...

How can my C/C++ application determine if the root user is executing the command?

Hello, I am writing an application that requires root user privileges to execute. If executed by a non root user, it exits and terminates with a perror message such as: pthread_getschedparam: Operation not permitted I would like to make the application more user friendly. As part of its early initialization I would like it to che...

Explain boost::filesystem's portable generic path format in C++

I am trying to understand portable generic path format and everything is not clicking. Can someone please explain this in terms of examples? I also have been told that I can use the forward slash in windows because windows understands both. Also is it considered good/safe style to use forward slash in windows? ...

no match for 'operator<' when trying to insert to a set (c++)?

I'm using gcc 4.3.3 to try to compile the following code: struct testStruct { int x; int y; bool operator<(testStruct &other) { return x < other.x; } testStruct(int x_, int y_) { x = x_; y = y_; } }; int main() { multiset<testStruct> setti; setti.insert(testStruct(10,10)); return 0; } I get this error...

Unresolved external symbol in c++

#include <iostream> #include <cstdlib> using std::cout; using std::endl; using std::rand; int man(){ int t=rand(); cout<<t<<endl; return 0; } here is code for generate random number in c++ and i have mistake 1>c:\users\david\documents\visual studio 2010\Projects\random_function\Debug\random_function.exe : fatal err...

Least Common Multiple of given numbers

Possible Duplicates: what is the most efficient way to calculate the least common multiple of two integers Least common multiple for 3 or more numbers Whats the simple logic for calculating LCM of given numbers? ...

C++: Why is the destructor being called here?

I guess I don't fully understand how destructors work in C++. Here is the sample program I wrote to recreate the issue: #include <iostream> #include <memory> #include <vector> using namespace std; struct Odp { int id; Odp(int id) { this->id = id; } ~Odp() { cout << "Destructing Odp " << id << ...

Non-Integer numbers in an String and using atoi

If there are non-number characters in a string and you call atoi [I'm assuming wtoi will do the same]. How will atoi treat the string? Lets say for an example I have the following strings: "20234543" "232B" "B" I'm sure that 1 will return the integer 20234543. What I'm curious is if 2 will return "232." [Thats what I need to solve ...

How do I turn relational comparison of pointers into an error?

We've been bitten by the following bug many times: #include <iostream> #include <vector> #include <algorithm> using namespace std; void print(int* pn) { cout << *pn << " "; } int main() { int* n1 = new int(1); int* n2 = new int(2); int* n3 = new int(3); vector<int*> v; v.push_back(n1); v.push_back(n2); v....

Is there a way to change the delete action on an existing instance of shared_ptr

I have a function where I want a cleanup action done 90% of the time, but in 10% I want some other action to be done. Is there some way to use some standard scoped control likeshared_ptr<> so that initially it can have one delete action and then later in the function the delete action can be changed? shared_ptr<T> ptr( new T, std::mem_...

referencing a vector::front works, but vector::begin doesn't

I have this bit of code: cerr << client->inventory.getMisc().front()->getName() << endl; vector<itemPtr>::iterator it; it = client->inventory.getMisc().begin(); cerr << (*it)->getName() << endl; Let me explain that a bit: client is a tr1::shared_ptr that points to an object that has a member named inventory that has a private vector...