c++

C++ extern class definition

I'm reading some code that goes: extern class MyClass : BaseClass { ... } MyInstance; Does the extern refer to the class declaration or the instance? ...

Organising .libs in a codebase of several C++ projects

Let's say you have several bespoke C++ projects in separate repositories or top-level directories in the same repository. Maybe 10 are library projects for stuff like graphics, database, maths, etc and 2 are actual applications using those libraries. What's the best way to organise those 2 application projects to have the .libs they nee...

Costs and benefits of Linux-like Windows development environment

I'm taking an Introduction to C++ this semester, so I need to set up development environments in both my Windows and Ubuntu partitions (I switch between them). I was planning to use GCC in both environments for consistency and because I plan to do my serious C++ developing in Linux with GCC. It appears that installing MSYS and MinGW is...

C++ difference of keywords 'typename' and 'class' in templates

For templates I have seen both declarations: template < typename T > And: template < class T > What's the difference? And what exactly do those keywords mean in the following example (taken from the German Wikipedia article about templates)? template < template < typename, typename > class Container, typename Type > class Exampl...

XCode debugger sucks; alternatives?

I've been programming on the Mac since I was a little kid using THINK C. I've never had to use a debugger as bad as the one that comes with XCode. It's unresponsive, and bogs down further and becomes unstable when watching more variables. When it crashes, I lose undo history for my sources because it's integrated with the editor. It do...

(C++ QT) QList only allows appending constant class objects?

I'm pretty new to QT. I've been messing with it for a week now. I came across a error while I was trying to add a custom datatype to a Qlist like so QObject parent; QList<MyInt*> myintarray; myintarray.append(new const MyInt(1,"intvar1",&parent)); myintarray.append(new const MyInt(2,"intvar2",&parent)); myintarray.append(new const MyI...

2-dimensional interpolation

I want to find a value of z at y = 12 and x = 3.5, given the below example data. How can I do this in C++? y = 10 x = [1,2, 3,4, 5,6] z = [2.3, 3.4, 5.6, 7.8, 9.6, 11.2] y = 20 x = [1,2, 3,4, 5,6] z = [4.3, 5.4, 7.6, 9.8, 11.6, 13.2] y = 30 x = [1,2, 3,4, 5,6] z = [6.3, 7.4, 8.6, 10.8, 13.6, 15.2] My current Python code: import...

c++ getting dynamic generic type of pointer?

Hi! the title probably is misleading, but i didn't really know how to name it. let's say I have the following structs template <typename T> struct SillyBase{ void doFunnyStuff(vector<T> vec){ dummyField = T(); for(int i=0; i<10; i++) vec.push_back(dummyField++); } T dummyField; }; struct A : pu...

Parsing a bit field parameter, how to "discard" bits in an unsigned long?

Hey all, First of all, I want to know if this is possible: let's say I have an unsigned long which contains some abritrary unsigned shorts, which may or may not be in the number. For example: unsigned short int id1 = 3456, id2 = 30998; unsigned long long bitfld = id1|id2; Can the other 2 fields be assumed as 0? An...

field has incomplete type

Hi, I got error of "field has incomplete type" but nor sure why. Can someone please help? Thanks! g++ -pipe -W -Wall -fopenmp -ggdb3 -DDEBUG -fno-omit-frame-pointer -c -o test.o ../../src/test.cc In file included from ../../src/test.cc:50: ../../src/feature_haar.h:14: error: field ‘_count’ has incomplete type test.cc #incl...

How should I handle "cast from ‘void*’ to ‘int’ loses precision" when compiling 32-bit code on 64-bit machine?

I have a package that compiles and works fine on a 32-bit machine. I am now trying to get it to compile on a 64-bit machine and find the following error- error: cast from ‘void*’ to ‘int’ loses precision Is there a compiler flag to suppress these errors? or do I have to manually edit these files to avoid these casts? ...

Warning "might be clobbered" on C++ object with setjmp

#include <setjmp.h> #include <vector> int main(int argc, char**) { std::vector<int> foo(argc); jmp_buf env; if (setjmp(env)) return 1; } Compiling the above code with GCC 4.4.1, g++ test.cc -Wextra -O1, gives this confusing warning: /usr/include/c++/4.4/bits/stl_vector.h: In function ‘int main(int, char**)’: /usr/include/c++/4.4...

What object is rethrown in C++?

I am quite confused about the type of the object which is rethrown in C++. For example, in the code above, why is the output 241? My understanding is that in Line 1, an object of class Bar is thrown. It is caught in Line 2. The object of type Bar is sliced to type of Foo. However, when the exception is rethrown, what's the type of tha...

Fast conversion from YUY2 to RGB24

Hello there! I'm writing a program, that will do some transformations with image from a webcam in real-time. As almost all other webcams, my noname gives data in YUY2 format (as written in bmiHeader.biCompression). I tried straight conversion on CPU side according to http://www.fourcc.org/yuv.php#YUY2, but it is VERY slow and wrong :). ...

How do i peek at at the next value of string iterator

In a loop running over the entire string how do i peek at the next value of iterator? for (string::iterator it = inp.begin(); it!= inp.end(); ++it) { // Just peek at the next value of it, without actually incrementing the iterator } This is quite simple in C, for (i = 0; i < strlen(str); ++i) { if (str[i] == str[i+1]) { ...

Debugging C++ virtual multiple inheritance in Visual Studio 2008 watch window

I'm having trouble debugging a project in Visual Studio C++ 2008 with pointers to objects that have virtual multiple inheritance. I'm unable to examine the fields in the derived class, if the pointer is a type of a base. A simple test case I made: class A { public: A() { a = 3; }; virtual ~A() {} int a; }; ...

C++ Language template question

Hi, Below is a small test case that demonstrates a problem that I am trying to solve using templates in C++: template<typename T> void unused(T const &) { /* Do nothing. */ } int main() { volatile bool x = false; unused(!x); // type of "!x" is bool } As written below, the g++ v3.4.6 compiler complains: test.cc: In constructor...

How to select default arguments that are passed to a function

I have a program here: I have a doubt in passing arguments to the function display(). void display(int = 20,int = 30,int = 50); int main() { display(5,12); return 0; } void display(int i,int j,int k) { cout<<i<<endl; cout<<j<<endl; cout<<k<<endl; } If this function display is called by passing 2 arguments to it, ...

What's the use of const here

in int salary() const { return mySalary; } as far as I understand const is for this pointer, but I'm not sure. Can any one tell me what is the use of const over here? Thanks ...

Need help with C++ templates

I'm fairly sure this is a template question, since I can't seem to solve it any other way - but non-template solutions are also welcome. A Finite State Machine has a number of program States and each state can react to a number of Events. So, I want to define classes for Event, State and FSM. FSM has a collection (probably vector, migh...