c++

Initializing qt resources embedded in static library

Hi folks, I have next situation: I need to create widget in standalone static library, which then will be linked with final application (visual c++ 9.0, qt 4.5). This static widget library contains some resources (icons), and consist of a several .cpp files (each contains standalone widget). As far as I know, i must initialize qt resour...

How to return NULL from a method in a Template Class

I have a method which looks like this: template <typename T> T Test<T>::FindItem(T item) { if(found) //return original value, no problem here else //I want to return NULL here, like: return NULL; } This fails in certain cases at runtime because some of the values can't be converted to NULL in C++ e.g.,...

How to get the cpu usage per thread on windows (win32)

Looking for Win32 API functions, C++ or Delphi sample code that tells me the CPU usage (percent and/or total CPU time) of a thread (not the total for a process). I have the thread ID. I know that Sysinternals Process Explorer can display this information, but I need this information inside my program. ...

Can I prevent invoking destructor before overloaded delete?

I'd like to use boost.pool. It's okay if you don't know about it. Basically, it has two main functions, malloc() and free(). I've overloaded new and delete for my custom defined class test. class test { public: test() { cout << "ctor" << endl; } ~test() { cout << "dtor" << endl; } vo...

Why people think that the only man who created C++ was Bjarne Stroustrup?

I am currently reading Stroustrup's book "Design and Evolution of C++" and it turns out that he was not the one who developed C++. When I hear someone saying "Bjarne Stroustrup developed C++ blah-blah-blah", I always feel it is very unfair to these guys who worked with BS - I mean Jonathan Shopiro, Andrew Koenig, Stan Lippman, Stefan Dew...

Initialising an anonymous mutex-lock-holding class instance in the LHS of a comma operator

Suppose I have code something like this: #include "boost/thread/mutex.hpp" using boost::mutex; typedef mutex::scoped_lock lock; mutex mut1, mut2; void Func() { // ... } void test_raiicomma_1() { lock mut1_lock(mut1); Func(); } void test_raiicomma_2() { (lock(mut1)), Func(); } void test_raiicomma_3() { (lock(mut1)), (lock(mut2...

scope vs ctags in terms of features

I am a big fan of ctags Hence I am wondering if I have cscope, will I benefit more there two programs. Seems like the latter has the same features as ctags, namely, facilitating the finding of symbols. What are the features scope offers that can further increase my productivity with VIM? Thanks ...

Get owner's access permissions using C++ and stat

How can I get the file owner's access permissions using stat from sys/stat.h using C++ in Kubuntu Linux? Currently, I get the type of file like this: struct stat results; stat(filename, &results); cout << "File type: "; if (S_ISDIR(results.st_mode)) cout << "Directory"; else if (S_ISREG(results.st_mode)) cout << "...

is it reasonable to program an algortihm without function calls ?

Hi there ... I am programming a an algorithm for a library and I didn't use function calls at all. The algorithm is about 100 lines and there is no duplicate code.or should I use inlining ? ...

How to add spin control to the dialog box using win32 C ?

just want to know how to add an spin control ( in another name, up/down control ) in the dialog box using C program (win32 / code::block / mingw compiler) ...

Why were references added to C++? (from the history viewpoint)

I've read many discussions on the difference between references and pointers and when to use which. They all seem to get their conclusions from analysis of the behaviors of the two. But I'd still like to know what was in the language designers' mind. What's the main motive for this design? In what typical situation is it intended to be ...

How to write a generic alert message using win32?

I just want to expand this following method into something more generic, which should accept any kind of argument and display it using MessageBox(): void alert(char *item) { MessageBox(NULL, item, "Message", MB_OK | MB_ICONINFORMATION); } Can anyone help? ...

macro and member function conflict

Hello, I have problem that,std::numeric_limits::min() conflicts with the "min" macro defined in "windef.h". Is there any way to resolve this conflict without undefine the "min" macro. The link below gives some hints, however I couldn't manage to use parenthesis with a static member function. What are some tricks I can use with macros?...

Singleton - Why use classes?

Just the other day I have seen code that uses the so called singleton pattern. Meaning something along the lines of class MySingleton{ public: void foo() { ... } static MySingleton return singleton } private: MySingleton(){ ... } ~MySingleton(){ ... } int bar; }; I do see why one would want to do that: ...

Understanding return value optimization and returning temporaries - C++

Please consider the three functions. std::string get_a_string() { return "hello"; } std::string get_a_string1() { return std::string("hello"); } std::string get_a_string2() { std::string str("hello"); return str; } Will RVO be applied in all the three cases? Is it OK to return a temporary like in the above code? I ...

.NET RegEx Performance vs. C++

Is there any published benchmark results about RegEx performance in .NET vs. unmanaged C++/C? ...

What GNU make substitute do you recommend?

Imagine you're free to choose a tool like GNU make for a new C++ project. What would you choose? Are any usable substitutes out there? It shall have/be a command line interface "easy" to understand ;) easy to set up for a default c++ project may support src/bin seperation as common for Java may not add too much dependencies to other s...

primary key declaration error while creating table

CreateL() { _LIT(KSQLCountry, "CREATE TABLE Country(CountryID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,CountryName VARCHAR(45) NOT NULL,CountryCode VARCHAR(10) NOT NULL)"); User::LeaveIfError(iDatabase.Execute(KSQLCountry)); } while creating table i want to declare for primary key and foreign key which showing run time error (it cr...

How to tame the Windows headers (useful defines)?

In one of the answers to this question jalf spoke about useful define NOMINMAX, that could prevent from unwanted defining min/max macros. Are there other useful defines that can help to control windows.h (or other Windows headers, for instance Microsoft C Runtime headers or STL implementation) behavior? ...

Slot seemingly not recognized in Qt app

Hello, I have been working on learning C++ and Qt4 recently, but I have hit a stumbling block. I have the following class and implementation: class Window : public QWidget { public: Window(); public slots: void run(); private: //... }; and Window::Window() { //... connect(runBtn,SIGNAL(clicked()),this,SLOT(run...