c++

Qt in visual studio: connecting slots and signals doesn't work.

Hi, I have installed Qt and Qt for VS plugin. Everything works fine, UI applications compile and run that's ok, but connecting signals and slots doesn't. I have Q_OBJECT in my class and for connecting I am using this code in constructor: connect(ui.mainTableView, SIGNAL(activated(const QModelIndex &)), this, SLOT(showDetail(con...

c++ volatile multithreading variables

I'm writing a C++ app. I have a class variable that more than one thread is writing to. In C++, anything that can be modified without the compiler "realizing" that it's being changed needs to be marked volatile right? So if my code is multi threaded, and one thread may write to a var while another reads from it, do I need to mark the v...

How to find the location of two consecutive spaces in a string

I want to check if my string has two consecutive spaces in it. What's the easiest way to find out? ...

Why was Cassandra written in Java ?

Question about Cassandra Why the hell on earth would anybody write a database ENGINE in Java ? I can understand why you would want to have a Java interface, but the engine... I was under the impression that there's nothing faster than C/C++, and that a database engine shouldn't be any slower than max speed, and certainly not use garba...

Windows mobile native exception C#/C++

I have a windows mobile solution which contains two projects. One written in C# and another in C++ (unmaneged code that compiles into a dll). The part written in C# invokes some C++ functions from dll to connect to a server. If I open my application and I connect to the server everything works ok. If I minimize it , or if I open anothe...

Where is the call to std::map::operator[] in this code?

I have the following typedef's in my code: typedef unsigned long int ulint; typedef std::map<ulint, particle> mapType; typedef std::vector< std::vector<mapType> > mapGridType; particle is a custom class with no default constructor. VS2008 gives me an error in this code: std::set<ulint> gridOM::ids(int filter) { std::set<ulint> r...

To which extent is "boost does it" equivalent to "very portable, use it"?

In this answer to a question asking "is doing Z this way portable" the idea is "boost does it this way, it means it is very portable". Can I just always consult boost sources to find the most portable way of doing something in C++? How can I judge for myself if boost is really such a collection of super-portable code? ...

Terminating app due to uncaught exception / / SIGABRT // C++ please help!

I have just finished one of my apps when I got this message. I cannot for the life of me work out what is wrong. (gdb) continue 2010-02-26 14:05:51.443 BrainTester[2638:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController _loadViewFromNibNamed:bundle:] was unable to load a nib ...

std::string formating like sprintf

Hi guys, I have to format std::string with sprintf and send it into file stream. How can I do this? ...

Loading C++ shared library through Java process on linux giving errors

(Developer environment: CentOS 4.7, KDevelop 3.1.1, gcc 3.4.6) I created a c++ shared library and a test executable that uses this shared library. Things work fine. But when I load this library through Java ie Java calls JNI which in turn loads this shared library, there is an error which states "* glibc detected * free(): invalid next...

What if I don't call ReleaseBuffer after GetBuffer?

From http://stackoverflow.com/questions/559483/cstring-to-char, ReleaseBuffer() must be used after GetBuffer(). But why? What will happen if I don't use ReleaseBuffer after GetBuffer()? Can somebody show me an example? Thanks. ...

C or C++ for Linux/UNIX daemon programming?

Dear stackoverflow, The topic basically says it all. I want to go more into writing daemons for Linux/UNIX systems and I want things to be fast and stable. Everything I look at seems to be written in C, however, some new projects seem to be using C++ a bit more. So if I were to start my own project, let's say a modular HTTP daemon, whi...

static member initialization for specialized template class

class A { }; template <typename A, int S> class B { public: static int a[S]; B() { a[0] = 0; } }; template<> int B<A, 1>::a[1]; int main() { B<A, 1> t; t; } It compiles under GCC 4.1, but does not link: static.cpp:(.text._ZN1BI1ALi1EEC1Ev[B<A, 1>::B()]+0x5): undefined...

C or C++ HTTP daemon in a thread?

I'm starting up a new embedded system design using FreeRTOS. My last one used eCos, which has a built-in HTTP server that's really lightweight, especially since I didn't have a filesystem. The way it worked, in short, was that every page was a CGI-like C function that got called when needed by the HTTP daemon. Specifically, you would ...

failed constructor and failed destructor in C++

Hi I have one question about failed constructor and failed destructor in C++. I noticed that when the constructor failed, an exception will be thrown. But there is no exception thrown in destructor. My question is 1) If constructor failed, what exception will be thrown? bad_alloc? or anything else related? Under what situation, a c...

Can you catch an exception by the type of a conversion operator?

I don't know how to phrase the question very well in a short subject line, so let me try a longer explanation. Suppose I have these exception classes: class ExceptionTypeA : public std::runtime_error { // stuff }; class ExceptionTypeB : public std::runtime_error { // stuff operator ExceptionTypeA() const; // conversion op...

Can you please explain this C++ delete problem?

I have the following code: std::string F() { WideString ws = GetMyWideString(); std::string ret; StringUtils::ConvertWideStringToUTF8(ws, ret); return ret; } WideString is a third-party class, so are StringUtils. They are a blackbox to me. Second parameter is passed by reference. When I step through the debugger the line ret...

How do I declare an array of objects whose class has no default constructor?

If a class has only one constructor with one parameter, how to declare an array? I know that vector is recommended in this case. For example, if I have a class class Foo{ public: Foo(int i) {} } How to declare an array or a vector which contains 10000 Foo objects? ...

C++ templated functor in lambda expression

This first piece has been solved by Eric's comments below but has led onto a secondary issue that I describe after the horizontal rule. Thanks Eric! I'm trying to pass a functor that is a templated class to the create_thread method of boost thread_group class along with two parameters to the functor. However I can't seem to get beyond m...

On multicore MacOSX, is the following c++ code threadsafe?

#define atomicAdd OSAtomicAdd32Barrier class PtrInterface: public Uncopyable { private: typedef volatile int RefCount; mutable RefCount rc; public: inline void newRef() const { atomicAdd(1, &rc); } inline void deleteRef() const { atomicAdd(-1, &rc); } }; [This is the basis of an invasive refcounted pointer; I just ...