This question might be more appropriately asked regarding C++ in general, but as I am using gcc on linux that's the context.
Consider the following program:
#include <iostream>
#include <map>
#include <string>
using namespace std;
template <typename TKey, typename TValue>
class Dictionary{
public:
map<TKey, TValue> internal;
...
I need to define some constant strings that will be used only by one class. It looks like I have three options:
Embed the strings directly into locations where they are used.
Define them as private static constant members of the class:
(Code formatting is buggy after enumerations.)
//A.h
class A {
private:
static const st...
My application is written in C++ and uses the Qt framework. I use the QAxWidget class to access an active x component. Now I need some kind of mechanism that notifies my application each time the active x component
has crashed or
does not respond any more (due to dead lock or infinite loop).
(1) can easily been done by watching the e...
I have a logger in a c++ application that uses defines as follows:
#define FINEST(...) Logger::Log(FINEST, _FILE, __LINE, __func, __VA_ARGS_)
However what I would like to do is to be able to switch off these logs since they have a serious performance impact on my system. And, it's not sufficient to simply have my Logger not write to ...
In my C++ application, I have some values that act as codes to represent other values. To translate the codes, I've been debating between using a switch statement or an stl map. The switch would look something like this:
int code;
int value;
switch(code)
{
case 1:
value = 10;
break;
case 2:
value = 15;
break;
}
The map...
Hi,
I have a class which has a private attribute vector rectVec;
class A {
private:
vector<Rect> rectVec;
};
My question is how can I return a 'read-only' copy of my Vector?
I am thinking of doing this:
class A {
public:
const vect<Rect>& getRectVec() { return rectVect; }
}
Is that the right way?
I am thinking this can guard...
I understand that CDT 7 will have a regular expression error parser included, but I'm using CDT 6 now.
I have an external CDT builder which just calls a shell script to trigger my build, (Jam-based). The build uses GCC, and the errors and warnings are streamed to a Console view, but of course no error parser is looking at it so nothing...
The answers to the following question describe the recommended usage of static_cast, dynamic_cast, and reinterpret_cast in C++:
http://stackoverflow.com/questions/332030/when-should-static-cast-dynamic-cast-and-reinterpret-cast-be-used
Do you know of any tools that can be used to detect misuse of these kinds of cast? Would a static ana...
As part of a new job, I have to devise and implement a complete test strategy for the company's new product. So far, all I really know about it is that it is written in C++, uses an SQL database and has a web API which is used by a browser client written using GWT.
As far as I know, there isn't much of an existing strategy, except for u...
Hi,
I am currently providing a static library using vs2008. I am in the process of building my static library. However, since I am using another static library is there a way that i package this as a single static library. The reason here is that they will be calling functions in my library that depend on that other static library (.li...
Is the following well-defined in C++, or not? I am forced to 'convert' exceptions to return codes (the API in question is used by many C users, so I need to make sure all C++ exceptions are caught & handled before control is returned to the caller).
enum ErrorCode {…};
ErrorCode dispatcher() {
try {
throw;
}
catch (std::b...
Hi,
In our application, we need to use a COM dll (namely msdia100.dll) which was not registered in the system before.
Earler, we have just called the DLL by calling its DllRegisterServer via this code:
// Register DIA DLL required by Breakpad
std::string diaLibPath = "msdia100";
HMODULE diaLib = LoadLibrary(diaLibPath.c_str());
if...
Under Vista, when in Basic theme, after calling IUIFramework::Destroy() the Vista theme is lost, and enlarging the window does not display outside of the initial area.
You can repro it easily with the SimpleRibbon SDK sample. In simpleribbon.cpp, insert in the WndProc switch block:
case WM_KEYUP:
DestroyFramework();
InvalidateRec...
This is a follow-up question to this one i made earlier. Btw thanks Neil Butterworth for you help
http://stackoverflow.com/questions/2461977/problem-compiling-c-in-codegear
A quick recap. Im currently developing a C++ program for university, I used Netbeans 6.8 on my personal computer (Mac) and all works perfect. When I try them on my...
I am working on a project that requires some image processing. The front end of the program is C# (cause the guys thought it is a lot simpler to make the UI in it). However, as the image processing part needs a lot of CPU juice I am making this part in C++.
The idea is to link it to the C# project and just call a function from a DLL to...
I am working on a project with a library and I must work with unions. Specifically I am working with SDL and the SDL_Event union. I need to make copies of the SDL_Events, and I could find no good information on overloading assignment operators with unions.
Provided that I can overload the assignment operator, should I manually sift thro...
Okay, so, the idea is that I have a map of "components", which inherit from componentBase, and are keyed on an ID unique to the most-derived*.
Only, I can't think of a good way to get this to work. I tried it with the constructor, but that doesn't work (Maybe I did it wrong). The problem with any virtual, etc, inheritance tricks are tha...
Is it a common pattern/idiom to use free functions as pseudo-constructors to avoid having to explicitly specify template parameters?
For example, everyone knows about std::make_pair, which uses its parameters to deduce the pair types:
template <class A, class B>
std::pair<A, B> make_pair(A a, B b)
{
return std::pair<A, B>(a, b);
}
/...
I'm a teacher(instructor) of CS in the university. The course is based on Cormen and Knuth and students program algorithms in C++. But sometimes it is good to show how an algorithm works or just a result of task through GUI. Also in my opinion it's very imporant to be able to write full programs. They will have courses concerning GUI but...
I have a 32-bit exe that needs to dynamically load a 64-bit dll when it detects that the operating system is 64-bit. Is this possible through LoadLibrary? If not, is there another way to accomplish the same goal?
...