c++

c++ constructor with new

I'm making a very dumb mistake just wrapping a pointer to some new'ed memory in a simple class. class Matrix { public: Matrix(int w,int h) : width(w),height(h) { data = new unsigned char[width*height]; } ~Matrix() { delete data; } Matrix& Matrix::operator=(const Matrix&p) { ...

standards compliant way to typedef my enums

How can I get rid of the warning, without explicitly scoping the enum properly? The standards-compliant code would be to compare against foo::bar::mUpload (see here), but the explicit scopes are really long and make the darn thing unreadable. maybe there's another way that doesn't use typedef? i don't want to modify the enum--i didn't w...

Differences between a `typename` parameterized template and and integral type one.

I've been trying to work with templates for a while now and the more I do the less I realise I understand. This latest problem feels like it has unearthed a rather fundamental misunderstanding on my part and I'm starting to think more than ever that, "Right, tomorrow I shouldn't write any code but instead find a library with a good CS se...

Summing all the numbers in a matrix revised

Hello I had recently asked a question about how to do the following: Write a function that sums all the integers in a matrix of integers using the following header: const int SIZE = 4; double sumMatrix (const double m [] [SIZE] , int rowSize, int columnSize) ; Write a test program that reads a 4-by-4 matrix and displays the sum of a...

Profiling embedded application

I have an application that runs on an embedded processor (ARM), and I'd like to profile the application to get an idea of where it's using system resources, like CPU, memory, IO, etc. The application is running on top of Linux, so I'm assuming there's a number of profiling applications available. Does anyone have any suggestions? Than...

Some final questions about inheritance/casting

I asked a question an hour or two ago that is similar but this is fundamentally different to me. After this I should be good. class base { private: string tame; public: void kaz(){} virtual ~base() {} void print() const { cout << tame << endl; } }; class derived: public base { private: string taok; p...

Simple MIPS Instructions and Compilers

Is it common for compilers (gcc for instance) to generate an instruction that loads some empty memory element into a register? Like... lw at,0(sp) where memory[sp + 0] = 0. This basically just places 0 into $at ($R1.) I ask because I'm looking through an executable file's hex dump (executable file is the result of the compilation of a...

C++ Vector Linking Problem

I keep getting the following link error on Visual Studio C++ 2010 Express, shape.obj : error LNK2019: unresolved external symbol "class std::vector<class rectangle,class std::allocator<class rectangle> > __cdecl rectangleIzer::rectanglizePolygon(class std::vector<class rectangleIzer::myPoint,class std::allocator<class rectangleIzer::my...

How do I use less CPU with loops?

Hi, I've got a loop that looks like this: while (elapsedTime < refreshRate) { timer.stopTimer(); elapsedTime=timer.getElapsedTime(); } I read something similar to this elsewhere (http://stackoverflow.com/questions/1222574/c-main-loop-without-100-cpu), but this loop is running a high resolution timer that must be accurate. So ...

C++ and returning a null - what worked in Java doesn't work in C++

So I'm having a rather tumultuous conversion to C++ from Java/C#. Even though I feel like I understand most of the basics, there are some big fat gaping holes in my understanding. For instance, consider the following function: Fruit& FruitBasket::getFruitByName(std::string fruitName) { std::map<std::string,Fruit>::iterator it = ...

What is the preferred STL collection when that's all you need?

I just need a "bag of things". It doesn't need to be a set, a map or even have any particular order. I just need to be able to add things and iterate over it, nothing more. I don't expect it to be very large but it can't get really bad perf if it does. What container should I use? ...

Executing member function of class through pointer to abstract parent of said class.

I have created an abstract base class Animal which has public virtual abstract method makeSound(). I created a subclass Cow which implements Animal.makeSound() as you would expect (you know... "moo"). And I have a Farm class which holds a private member variable std::vector<Animal*> animals. In one of the Farm methods I iterate over a...

float to _bstr_t

I know I can create a _bstr_t with a float by doing: mValue = _bstr_t(flt); And I can format the float string by first declaring a c string: char* str = new char[30]; sprintf(str, "%.7g", flt); mValue = _bstr_t(str); I am a bit rusty on c++, especially when it comes to _bstr_t which is A C++ class wrapper for the Visual Basic str...

What does C++ add to C?

What does C++ add to C? What features of the language are the Clang/LLVM projects, the parts of GCC that are being written in C++, chromium, and any others all taking advantage of? What features are they avoiding? ...

Eclipse CDT Build Configs - Testing a DLL with CPP Unit

Hi, I'm making a DLL (and probably a Linux port at some later date) in C++ using eclipse. The situation is as follows: I am trying to make two separate build configurations, one that will build a DLL and one that will build an executable CppUnit test. Currently I have all of the DLL build working, and I can make a separate project to te...

Calling a python method from C/C++, and extracting its return value.

I'd like to call a custom function that is defined in a python module from C. I have some preliminary code to do that, but it just prints the output to stdout. mytest.py import math def myabs(x): return math.fabs(x) test.cpp #include <Python.h> int main() { Py_Initialize(); PyRun_SimpleString("import sys; sys.path.appe...

Help understanding class example code for C++, templates, operator()

I'm not sure exactly what the following class does that we have for a class example. In the following code, what does the operator() do in this case? I don't quite get the *(begin + first) and pretty much the whole return expression as what is being evaluated. Any help would be great. Thanks! // IndexCompare.h - interface for IndexC...

Which features of C++ are particularly resource intensive at compile time?

I believe C is generally faster to compile than C++, because it lacks features like late binding and operator overloading. I'm interested in knowing which features of C++ tend to slow the compilation process the most? ...

Zooming into the mouse, factoring in a camera translation? (OpenGL)

Here is my issue, I have a scale point, which is the unprojected mouse position. I also have a "camera which basically translates all objects by X and Y. What I want to do is achieve zooming into mouse position. I'v tried this: 1. Find the mouse's x and y coordinates 2. Translate by (x,y,0) to put the origin at those coordinates...

Reading a file to a string in C++

As somebody who is new to C++ and coming from a python background, I am trying to translate the code below to C++ f = open('transit_test.py') s = f.read() What is the shortest C++ idiom to do something like this? ...