c++

On the use (and usefulness) of a pointer to member function vs directly calling the member function

I am new to pointer to member functions, and I would like to know their pros and cons. Specifically, consider this: #include <iostream> #include <list> using namespace std; class VariableContainer; class Variable { public: Variable (int v) : value (v), cb_pointer (0) {} ~Variable () {} void SetCallback (void (VariableContaine...

what does "BUS_ADRALN - Invalid address alignment" error means?

We are on HPUX and my code is in C++. We am getting "BUS_ADRALN - Invalid address alignment" in my executable on a function call. What does this error means? Same function is working many times then suddenly its giving core dump. in GDB when i try to print the object values it says not in context. Any clue where to check? Thanks in Adv...

Dynamic Creation in Qt of QSlider with associated QLCDNumber

I was wondering what's the best way to go about the following scenario? I am dynamically creating QSliders that I wish to link to an associated QLCDNumber for display. The thing is I would like to have tenths available, so I would like to have a conversion between the QSLider and the QLCDNumber to divide by 10. At this point all I keep ...

Parsing .c/.cpp/.py source files in Python to get a list of the functions contained

I'm trying to learn about parsers, for Python, C and C++ source (on my own, not for a school project). Here is a summary of what i want to do: 1) read .c/.cpp/.py source files in Python 2) get a list of all the functions in the source files, and the span of their definitions in terms of line numbers. So to illustrate my question, con...

Is there a better way to initialize an allocated array in C++?

How to write this in another (perhaps shorter) way? Is there a better way to initialize an allocated array in C++? int main(void) { int* a; a = new int[10]; for (int i=0; i < 10; ++i) a[i] = 0; } ...

C++ / Objective-C : The two files of a class are called Header and ...?

In languages like C++ or Objective-C a class normally consist of two files. The first is called Header or Interface but what is the "official" name of the other file? In some books it's just called "Codefile" in other "implementation file" or "message file" for Objective-C. Which name is the right name? I need to write a tutorials and I...

How to get the Window Class Name and Id from HWND?

How to get the Window Class Name and Id from HWND? I searched but found the opposite is more popular. Any thoughts?!?!? ...

C++ - pointer passing question

Does somebody have any idead on how to pass boost::shared_ptr - by value or by reference. On my platform (32bit) sizeof(shared_ptr) equals 8 bytes and it looks like I should pass them by reference, but maybe somebody has another opinion / did a profile / something like that? ...

Protected vs Private Destructor

Is there any difference between a protected and a private destructor in C++? If a base classes destructor is private, I imagine that it is still called when deleting the derived class object. ...

A question on #define for class

I have always seen people writes class.h #ifndef CLASS_H #define CLASS_H //blah blah blah #endif The question is why don't they do that too for the .cpp file that contain definition for class functions? Let's say I have a main.cpp, and main.cpp import class.h. class.h do not import anything, so how can the main.cpp knows what is i...

How can I check for existence of element in std::vector, in one sentence?

Possible Duplicate: How to find an item in a std::vector? This is what I'm looking for: #include <vector> std::vector<int> foo() { // to create and return a vector return std::vector<int>(); } void bar() { if (foo().has(123)) { // it's not possible now, but how? // do something } } In other words, I'm looking fo...

Can parentheses take arbitrary identifiers as arguments? C++

For example, is (const int)* someInt; valid code? If so, is that statement different than const int* someInt; ? ...

Can I increase int i by more than one using the i++ syntax?

Hi int fkt(int &i) { return i++; } int main() { int i = 5; printf("%d ", fkt(i)); printf("%d ", fkt(i)); printf("%d ", fkt(i)); } prints '5 6 7 '. Say I want to print '5 7 9 ' like this, is it possible to do it in a similar way without a temporary variable in fkt()? (A temporary variable would marginally decrease efficiency...

Mobile Broadband - run the mbapi sample

I am trying to run the mobile broadband sample "mbapi" from the Microsoft SDKs\Windows\v7.0\samples\netds\MB\mbapi, but I receive the following error code (I ran it with the EnumerateInterfaces switch): Error message “0x80070490 Element not found” File mbapi.cpp, Line: 240 (“hr = g_InterfaceMgr->GetInterfaces(&psa);”) Can someone help m...

How to customize the display of a QListView

Hi, I have implemented a list of users in my Qt program, using the model/view principle of Qt. My QListView displays a subclass of QAbstractListModel and so far this works just fine. Now I would like to customize the display of my user list (display the name on several line, add IP information, and so on: not really relevant, I just wa...

c++ vector pointer

How do i make vector which will have pointers in it? Tried this but failed. vector<*struct_gene> vector_child_genes; full code if some one is interested http://codepad.org/50qrNZvd ...

C++ friend operator overload doesn't compile.

I have the following (cut-down) class definition, and it has compilation errors. #include <iostream> #include <string> class number { public: friend std::ostream &operator << (std::ostream &s, const number &num); friend std::string &operator << (std::string, const number &num); friend std::istream &opera...

const int = int const ?

For example, is int const x = 3; valid code? If so, does it mean the same as const int x = 3; ? ...

a way to omit taking names for objects that are used only to construct a final object

Suppose we have following two classes: class Temp{ public: char a; char b; }; class Final{ private: int a; char b; char c; public: Final(Temp in):b(in.a),c(in.b){} //rest of implementation }; suppose the only use of objects of Temp class is to construct objects of Final class, so I wonder if in current standard of c++...

Can we replace our ODBC import with an OLEDB import?

I'm looking for some advice/information from people far more familiar with database connectivity technology than I am. Currently our app allows the user to select any ODBC dsn on their machine, choose a table and optionally specific columns from the table and import them into our app using ODBC. In our new version we are creating a 64 b...