c++

best data structure for byIndex and byName retrieval

suppose you need to implement container of a T items, which its value could be retrieved by numeric index (which is random access) and by name (as string). which one is better in term of performance of common operation such as retrieval, adding, and removing the items: (in this case retrieval by index need to be implemented by walking...

How to keep one of my application windows on top of the other windows of the same application?

I have a Motif-based notepad-like legacy application. I would like the modeless "Find/Replace" dialog (which is a Motif TopLevelShell) to always stay on top of the other windows of my application, but not on top of other applications. I don't see any Motif-specific setting to do this. KDE allows me to set window-specific behavior, but ...

C++ link error on Visual Studio 2010 x64

I'm upgrading a C++ code base from VS2005 to VS2010 and I'm rebuilding some third party C++ dependencies. I have no problem building these 32-bit but keep running into problems linking 64-bit (x64). I'm getting unresolved externals for a number of standard library functions. For example: error LNK2001: unresolved external symbol "__decl...

How to avoid writing multiple versions of the same loop

Inside a large loop, I currently have a statement similar to if (ptr == NULL || ptr->calculate() > 5) {do something} where ptr is an object pointer set before the loop and never changed. I would like to avoid comparing ptr to NULL in every iteration of the loop. (The current final program does that, right?) A simple solution woul...

Can a Windows app compiled using the Unicode character set use a DLL compiled as Multi-Byte?

I suspect the answer is "no", since when I go to include the header, the "T" macros will be defined to use (wchar_t *), but the DLL is expecting (char *). However, I was wondering whether Windows did any on-the-fly transcoding between modules that would make this magically work (assuming simple ASCII characters). ...

C++. Class method pointers

There is a class class A { public: A() {}; private: void func1( int ) {}; void func2( int) {}; }; I want to add a function pointer which will be set in constructor and points to func1 or func2. So I can call this pointer (as class member) from every class procedure and set this pointer in constructor. How can I do it...

Do Pdb files contains public function's arguments name?

Hello, I need to look up function argument names of public methods. Types are easily available from PDB symbols or DIA symbols. But Is there any way out by which we can trace and pull out function arguments names as well? I am concirned with native pdb symbols. Regards Usman ...

Are there any existing tools to convert c++ header files to header + implementation?

I tend to prototype C++ classes as a self-contained class, i.e. like: class BlahBlahBlah { public: void SomeMethod() { // some code here } }; and then later when I am happy with the design I will turn it into a .h/.cpp pair. This is mostly a mechanical task so is there any tool out there that can help with that? ...

"templating" a namespace

Hi, I'd like to build something like this: File 1: template<typename Vector> namespace myNamespace { class myClass1{ myClass1(Vector v) {...} } } File 2: template<typename Vector> namespace myNamespace { class myClass2{ myClass2(Vector v) {...} } } Of course this is not possible because you cannot template namespaces. Instead I ...

std::vector<std::vector<type>> for sparse matrix structure or something else?

I am implementing a sparse matrix class in compressed row format. This means i have a fixed number of rows and each row consists of a number of elements (this number can be different for different rows but will not change after the matrix has been initialised. Is it suitable to implement this via vectors of vectors or will this somehow ...

RegQueryValueExW only brings back one value from registry

I am querying the registry on Windows CE. I want to pull back the DhcpDNS value from the TcpIp area of the registry, which works. What happens though, however, is if there is two values - displayed as "x.x.x.x" "x.x.x.x" in my CE registry editor - then it only brings back one of them. I am sure this is a silly mistake but I am unsure ...

Ambiguous operator <<

Guys having code : #include "stdafx.h" #include "Record.h" template<class T>//If I make instead of template regular fnc this compiles //otherwise I'm getting an error (listed on the very bottom) saying // that operator << is ambiguous, WHY? ostream& operator<<(ostream& out, const T& obj) { out << "Price: " << (obj.getP...

C++: Why does my DerivedClass's constructor not have access to the BaseClass's protected field?

I have a constructor attempting to initialize a field in a base class. The compiler complains. The field is protected, so derived classes should have access. //The base class: class BaseClass { public: BaseClass(std::string); BaseClass(const BaseClass& orig); virtual ~BaseClass(); const std::string GetData() const; ...

Sorting the three integers program

I have tried to write my program, but it doesnt come out the way I want it, can some one please revise this source code fully to show how the corrections fit in. Heres the problem: Write a program that sorts three integers. The integers are entered from the console and stored in variables numi, num2, num3, respectively. The program sort...

How to implement two periodical processes in C++ under Linux?

Hello, I am doing real time programming in C++, under Linux. I have two process, let me say A and B. A process is being started periodically, every 5ms. B process is being started every 10ms. The process A is doing some change of data. The process B is reading that data and displays it. I am confused about how to run periodically pro...

C++ template duck-typing vs pure virtual base class inheritance

Which are the guidelines for choosing between template duck-typing and pure virtual base class inheritance? Examples: // templates class duck { void sing() { std::cout << "quack\n"; } }; template<typename bird> void somefunc(const bird& b) { b.sing(); } // pure virtual base class class bird { virtual void sing() = 0; }; c...

Where can I read more about memory structure in C++?

I came across this presentation while browsing SO some time ago, and it relates performance to specific memory allocation decisions. The author has some interesting diagrams that show how various objects are allocated by a C++ program, and goes on to optimise the program by making some changes in the code. His diagrams make sense in thei...

Pointer to object

I have the following: class Person { public: char Name[20]; char Surname[20]; char Address[256]; }; Person myperson; myperson.Name = "Andy"; Person * p_person = new Person(); AlterPersonFunction(p_person); //Coming out of AlterPersonFunction myperson now contains values of p_pers??? void AlterPersonFunction(Person *p_pe...

Performance - checking if container is empty before doing operations on it?

Is there a significant difference between doing this... if ( !myVector.empty()) { for ( unsigned int i = 0; i < myVector.size(); ++i ) { // do stuff } } and this for ( unsigned int i = 0; i < myVector.size(); ++i ) { // do stuff } if the vector is empty? What is the cost of this on an empty vector? ...

Class Hierarchy .

Please don't mind about the syntax. I thought of making the post as brief as possible. We have a class hierarchy as below. // abstract class. class BaseProd // concrete classes. class Prod1 : public BaseProd class Prod2 : public BaseProd class Prod3 : public BaseProd Each class has 3 sub classes like, Prod1New, Prod...