c++

C++: Construct subclass from base class instance?

I have three structs, one of which inherits from the other two: typedef struct _abc { int A; int B; int C; } ABC; typedef struct _def { int D; int E; int F; } DEF; typedef struct _abcdef : ABC, DEF { } ABCDEF; (I want the third struct to contain all the members of the first two. Is there a better way to do i...

Language feature comparison: Java to C++

I have a need to learn the stuff that James Gosling took out of C/C++ to make Java. For example: The way you can't overload operators in Java. The way you can't have multiple-inheritance in Java. The way that dependencies are handled quite a bit differently in C++ than in Java. ...

Generating Java binding to a Qt based library

I'm writing a Qt based (QtCore) C++ library and would like to have access to it from Java and Python. Python is not a problem because of PySide and SIP. But I can't seem to find any information about doing the same with Java. The fact that Java bindings exist for Qt makes me hopefuly that there is a way to create bindings for a custom Qt...

Assigning value passed by reference to a member variable (in C++)

I am trying to wrap my head about scope in C++. Please consider the following: class C { int i_; public: C() { i_ = 0;} C(int i) { i_ = i; } C(const C &c) { i_ = c.i_; cout << "C is being copied: " << i_ << endl; } int getI() { return i_; } ~C() {cout << "dstr: " << i_ << endl;} }; class D { ...

Automated testing of C++ console app in Visual Studio by sending text files to stdin?

Hi, I am going to take part in a coding contest my University is organizining next week. I am only allowed to use C or C++ and I would prefer to use the latter one using Visual Studio 2010. For every task there is a text input provided as plaintext to stdin, for example: 200 100 10 2 11 I need a tool which would assist me with ...

error C2039: 'string' : is not a member of 'std', header file problem

I am having problems with a class I am writing. I have split the class into a .h file that defines the class and an .cpp file that implements the class. I receive this error in Visual Studio 2010 Express: error C2039: 'string' : is not a member of 'std' This is the header FMAT.h class string; class FMAT { public: FMAT(); ~...

C++ template argument inference and string literals

I have a "set" data type: template <class V> struct Set { void add(const V& value) {} }; I want to write a top-level function version of Set::add. template <class V> void add(const Set<V>& set, const V& value) {} This doesn't quite work with string literals: Set<const char*> set; const char* val = "a"; set.add(val); // ok set.a...

[Nokia N900] How can you detect the pressure with which the screen is pressed ?

Hey all .. i wanted to know, in C++/Qt, how can one detect with how much pressure the screen is being pressed when a project is on the N900 ?.. Can anyone help me on this ? ...

Opening a file from a Qt String

I am making a Qt application and I have a button to open a file, which is connected to a custom slot. This is the slot code so far: void MainWindow::file_dialog() { const QFileDialog *fd; const QString filename = fd->getOpenFileName(); } How could I have it then convert the file name to a const char *, open the file, read it a...

std::map assignment of read only location

I have a static std::map<std::string, CreateGUIFunc> in a class that basically holds strings identifying gui types, and CreateGUIFunc is a reference to a factory function. In my constructor I have if ( m_factoryRef.size() == 0 ) { m_factoryRef["image"] = &CreateGUI<Image>; m_factoryRef["button"] = &CreateGUI<Button>; } ... Howeve...

In which case if(a=b) is a good idea?

Possible Duplicate: Inadvertent use of = instead of == C++ Compilers let your know via warnings that you wrote if( a = b ) { //... and that it might be a mistake, that you certainly wanted to write if( a == b ) { //... But is there a case where the warning should be ignored because it's a good way to use this "feature"?...

Boost C++ regex - how to get multiple matches

If I have a simple regex pattern like "ab." and I have a string that has multiple matches like "abc abd". If I do the following... boost::match_flag_type flags = boost::match_default; boost::cmatch mcMatch; boost::regex_search("abc abd", mcMatch, "ab.", flags) Then mcMatch contains just the first "abc" result. How can I get all ...

Using volatile long as an atomic

If I have something like this... volatile long something_global = 0; long some_public_func() { return something_global++; } Would it be reasonable to expect this code to not break (race condition) when accessed with multiple threads? If it's not standard, could it still be done as a reasonable assumption about modern compilers? ...

What do you call a single header whose purpose is to include other header files?

I've seen this done before in various C++ libraries - namely Qt (QtCore, QtGui, etc.) and Irrlicht (irrlicht.h): // file - mylibrary.h #include "someclass1.h" #include "someclass2.h" #include "someclass3.h" // and so on... Obviously this exists for convenience - a programmer wishing to use the library only has to include one header i...

How do I get the giomm-2.4 package?

Hello, I am trying to build a GTK application (c++) using NetBeans. After including the gtkmm.h file I had to use the pkg-config tool to determine what it's dependencies where. I then added them to the included folders. Netbean complains that it cannot find 'giomm-2.4'. This package does not exist in /usr/lib and I cannot seem to find t...

need help in making toolbar using MFC

i added this in my header file CToolBar myBar; public: int OnCreate(LPCREATESTRUCT lpCreateStruct); void OnToolBarButton1(); void OnToolBarButton2(); and i added this in .cpp file BEGIN_MESSAGE_MAP(CtoolbarfDlg, CDialog) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_WM_CREATE() ON_COMMAND(IDC_...

understanding Functors in STL

quoting from "The C++ Standard Library" by N M Jousttis, Section 5.9 #include < iostream> #include < list> #include < algorithm> using namespace std; //function object that adds the value with which it is initialized class AddValue { private: int the Value; //the value to add public: //constructor initializes t...

Radio style instead of MF_CHECKED for menu item?

I noticed some applications have a blue circular instead of a checkmark which MF_CHECKED produces. Which style produces this circular one? Thanks ...

Memory leak checking using Instruments on Mac

I've just been pulling my hair out trying to make Instruments cough up my deliberately constructed memory leaks. My test example looks like this: class Leaker { public: char *_array; Leaker() { _array=new char[1000]; } ~Leaker() { } }; void *leaker() { void *p=malloc(1000); int *pa=new int[...

Migrating to Xcode and now having lots of "is not member of std" and some other header problems

Hi! I am migrating to OS X and now trying to use Xcode. There is a project that was compiling and running normally on a g++ linux distro, now on mac it is returning a thousand of errors. I guess that the linux std files, somehow included others files needed and now they are not this connected in the std of Mac OS X. How can I know what ...