c++

Migrating from C# to C++

Possible Duplicate: How to learn C++ as a C# programmer? My new job needs me to migrate from C# to C++. I am comfortable with C# and have an exposure to C++ at college (basics). What would be the best way to go forward. Please suggest some materials or books to go forward. ...

Is there any time estimation about sqlite3's open speed?

I am using SQLite3 in C++, I found the opening time of sqlite seems unstable at the first time (by that I mean the time to open windows and open the db at the first time). It takes a long time on 50M db, about 10s in windows, and vary on different times. Has any one met the same problem? I am writing a desktop application in windows, ...

While within a switch block

Hi, I've seen the following code, taken from the libb64 project. I'm trying to understand what is the purpose of the while loop within the switch block - switch (state_in->step) { while (1) { case step_a: do { if (codechar == code_in+length_in) { st...

compiler warning at C++ template base class

I get a compiler warning, that I don't understand in that context, when I compile the "Child.cpp" from the following code. (Don't wonder: I stripped off my class declarations to the bare minuum, so the content will not make much sense, but you will see the problem quicker). I get the warning with VS2003 and VS2008 on the highest warning ...

Detect pointer arithmetics because of LARGEADDRESSAWARE

I would like to switch my application to LARGEADDRESSAWARE. One of issues to watch for is pointer arithmetic, as pointer difference can no longer be represented as signed 32b. Is there some way how to find automatically all instances of pointer subtraction in a large C++ project? If not, is there some "least effort" manual or semi-auto...

Pause the log4c++ logger

Hi, is it possible to pause the logger in log4c++, and by pause I mean to stop writing messages in the log file but not finalize the logger object or delete it. thanks in advance ...

Socket send recv functions

I have created a socket using the following lines of code. Now i change the value of the socket i get like this m_Socket++; Even now the send recv socket functions succeeds without throwing SOCKET_ERROR. I expect that it must throw error. Am i doing something wrong. struct sockaddr_in ServerSock; // Socket a...

Strange iterator behaviour

#include "stdafx.h" int _tmain(int argc, _TCHAR* argv[]) { string s = "Haven't got an idea why."; auto beg = s.begin(); auto end = s.end(); while (beg < end) { cout << *beg << '\n'; if (*beg == 'a') {//whithout if construct it works perfectly beg = s.erase(beg); } ...

Template class that refers to itself as a template template parameter?

This code: template <template <typename> class T> class A { }; template <typename T> class B { A<B> x; }; doesn't compile, I suppose since A<B> is interpreted as A<B<T> > within B's scope. So, how do you pass B as a template template parameter within it's scope? ...

How to iterate over a STL set and selectively remove elements?

The following code does not work correctly. How should it be done correctly? for (std::set<Color>::iterator i = myColorContainer.begin(); i!=myColorContainer.end(); ++i) { if ( *i == Yellow) { DoSomeProccessing( *i ); myColorContainer.erase(i); } } ...

sending sms from windows application

I am creating a windows application which needs to send some sms to mobile phone.This is just for testing purpose. Now can I use my cell phone to get this done. I have android phone which can be connected to pc using USB. Application is created in C++, windows api. Any pointers will help ...

Trouble with boost signals

Hello, I have such situation in boost and C++: // Somewhere: typedef boost::signals2::signal<void (int KeyCode)> SigKeyPressed; typedef SigKeyPressed::slot_type SigKeyPressedType; class InputSystem { private: static SigKeyPressed mSigKeyPressed; public: static boost::signals2::connection keyPressed(const SigKeyPressed...

Explicit specialization in non-namespace scope

template<typename T> class CConstraint { public: CConstraint() { } virtual ~CConstraint() { } template <typename TL> void Verify(int position, int constraints[]) { } template <> void Verify<int>(int, int[]) { } }; Compiling this under g++ gives the following error: Explicit specialization in non-namespace scope 'class CConstrain...

typedef boost::shared_ptr<MyJob> Ptr; or #define Ptr boost::shared_ptr

I've just started working on a new codebase where each class contains a shared_ptr typedef (similar to this) like: typedef boost::shared_ptr<MyClass> Ptr; Is the only purpose to save typing boost::shared_ptr? If that is the case, is the only reason not to do #define Ptr boost::shared_ptr in one common header the general problem...

c++ - strange problem with polymorphism - cellular automaton

Hello, I am making "game of life" implementation that, when cell has: two live neighbours I make object of class CCellB two live neighbours I make object of class CCellA when has >3 or <2 I make object of class CCellX (dead) Class CCell is base of CCellA, CCellB, CCellX arr is previous state of game, temp will be new arr at the end. ...

How to select a random element in std::set?

How can I select a random element in an std::set? I naively tried this: int GetSample(const std::set<int>& s) { double r = rand() % s.size(); return *(s.begin() + r); // compile error } But the operator+ is not allowed in this way. ...

How do I sort a file that has a very long list of items?

I have a text file that has a very long list of items. So I want to sort them alphabetically but I do not want to load all the file into the memory (RAM). I tried loading all the contents of the file to an array and sort them just like I do normally. But the system complains that there are no much memory!! Thanks, Mohammad ...

Do I have to initialize simple class member variables?

Quick beginner's question: Do I have to initialize simple class member variables, or are they guaranteed to get assigned their default values in any case? Example: class Foo { int i; // is i==0 or do I need the following line for that? Foo() : i(0) {} }; Thanks! ...

C++ and virtual methods overriding

Sorry for this stupid question, but I can't find an answer by myself, I'm too new in C++ :( class DBObject : public QObject { ... protected: virtual QString tableName() = 0; }; class DBUserObject : public DBObject { ... protected: virtual QString tableName() { return "profiles"; }; }; And I have this code in parent: ...

Retrieve Heap memory size and its usage statistics etc...?

Lets say I open some application or process. Did some work with that. Now I closed it. Need to know whether this application caused any memory leak. i.e used up some heap memory and not cleared it properly. Can I get this statistics some how? I'm using Visual Studio (for development) under Windows OS. Even I would be interested in kno...