c++

Initializing class without default constructor

If I have a class A with only a copy constructor and a constructor with parameters int and int, and I place that class inside a class B: class B { public: B(); private A a; } How would I initialize a inside B's constructor? I've tried a(0, 0), a = A(0, 0), but not surprisingly neither worked, and I receive a error: no match...

Tokenization of a text file with frequency and line occurrence. Using C++.

Hello, once again I ask for help. I haven't coded anything for sometime! Now I have a text file filled with random gibberish. I already have a basic idea on how I will count the number of occurrences per word. What really stumps me is how I will determine what line the word is in. Gut instinct tells me to look for the newline character...

Does the Poco C++ Library Support positional command line arguments?

I can see no way to support positional command line arguments with Poco's Poco::Util::Application class and related Poco::Util::OptionProcessor. Positional arguments are unnamed arguments on the command line, coming at the end after all other options, as such: someprogram -b --what=121 filename.bin In that example, filename.bin is a p...

Vector sorting: swap overload

I would like to overload swap function for std::vector of primitive types / objects. The reason is a slow sorting of vectors containing big objects using std::sort. Here is the simple but not working example. #include <vector> #include <algorithm> class Point { private: double x, y; public: Point(double xx, double yy) : x(xx), y...

C++ template static member instantiation

#include <map> #include <iostream> template <typename T> class A { static std::map<int, int> data; public: A() { std::cout << data.size() << std::endl; data[3] = 4; } }; template <typename T> std::map<int, int> A<T>::data; //std::map<int, int> A<char>::data; A<char> a; int main() { return 0; } What is wrong with this? Wit...

Do Explicit Instantiations of C++ Class Templates Instantiate Dependent Base Classes?

I figured an explicit instantiation request would automatically instantiate all base class members also, but I get a linker error: unresolved external symbol "public: void Base<int>::foo(int)" when building this code using Visual Studio 2008 or 2010. Note that adding a call to foo() inside bar() forces the compiler to instantiate Base<i...

Argument forwarding for no argument cases.

I have a class like this: template<class T> class A : public T { // this is done to wrap the base class version of a virtual function virtual void F(int i) { if(i < 0) T::F(-i); else T::F(i); } //... that needs to be constructible for any set of args the base class can be constructed with: template <typename T1> A(T1 t1) : T(...

Is it slow on the iPhone to do a lot of mallocs and frees?

Hey guys, I was working on some particle systems and this was the only way I could figure out to set up the arrays: if (vertices){ free(vertices); } if (textures){ free(textures); } vertices = malloc(sizeof(point3D) * 4 * [particles count]); textures = malloc(sizeof(point2D) * 4 * [particles count]); The particles constantly ...

Call c++ member function with each element in a list?

I have a list of Thing and a Controller that I want to notify() with each of the things. The code below works: #include <algorithm> #include <iostream> #include <tr1/functional> #include <list> using namespace std; class Thing { public: int x; }; class Controller { public: void notify(Thing& t) { cerr << t.x << endl; } }; class N...

Write an overloaded operator+ function so that two instances of the quadratic class can be added together as in the following code:

Write an overloaded operator+ function so that two instances of the quadratic class can be added together as in the following code: quadratic y1 = quadratic (1.0, -5.0, 7.0); quadratic y2 = quadratic (-3.0, -2.0, 10.0); quadratic y3; double result; y3 = y1 + y2; result = y1.evaluate (10.0); cout << result <<endl; To help you out, her...

Good software for software planning?

Is there software that can help create flow charts, class diagrams etc to help software development planning. Thanks ...

Operator Overloading Questions

So my prof has a sample .h file with the following operators at the end //ComplexNumber.h #include <iostream> using namespace std; #ifndef MY_COMPLEX_H #define MY_COMPLEX_H class complexNumber { public: complexNumber(); complexNumber(double a, double b); void setReal(double a); void setImaginary(double b); double ...

Code Blocks, Mingw, Boost, and static linking issues.

I am using Code Blocks with mingw and am trying to get a simple program to compile with static linking. I have build the boost libraries using these directions, here. Everything worked out fine and i was able to successfully compile this simple program (it compiles, i know it doesn't work because it exits before the message is sent to ...

c++ - Can a cast cause a buffer overrun?

Is it possible for a buffer overflow to occur from a cast? If so, please explain how. thanks. ...

C++ Pointer Trouble

So I have this array of pointers image* [] myArray; And I copy the objects in the array into a new, larger array. for (int i=0; i<maxObjects; i++){ newArray[i] = myImages[i]; } for (int i=maxObjects; i<newMaxObjects; i++){ newArray[i] = NULL; } The point of this is to resize my array. Then I delete myArray: delete [] myArray;...

Why doesn't Xcode + Instrument Leaks detect this leak in simple C++ program

I have the following in a simple C++ console project in Xcode. When I run this with instrument Leaks, Xcode does not flag any memory leaks even thought there is a glaring one. What is going on ? Any help? #include <iostream> int main (int argc, char * const argv[]) { // insert code here... int *x = new int[20]; x[0] = 10; ...

Include Linux header file

How could I include a linux header file? I read from the web that the header file is in /usr/include. However, the header file I need is not in that directory; it is in /usr/src/kernels/2.6.32.../include/linux/. I tried to include the file using the full path. However, the file itself includes other header files as well. Hence, the com...

C++ - LNK2019 error unresolved external symbol [template class's constructor and destructor] referenced in function _main

[[UPDATE]] -> If I #include "Queue.cpp" in my program.cpp, it works just fine. This shouldn't be necessary, right? Hey all -- I'm using Visual Studio 2010 and having trouble linking a quick-and-dirty Queue implementation. I started with an empty Win32 Console Application, and all files are present in the project. For verbosity, here's t...

Usefulness of template metaprogramming

Possible Duplicate: What's the use of metaprogramming? I see a lot of guys here talking about Template Metaprogramming here at SO. But I still don't get how is it useful? Where can it be used and why? Please don't close this question as a dupe to this because the latter does not answer my question. ...

Run the same C++ Program from different Binary Names

Okay, for a homework assignment my professor wants us to write a program in C++ that converts from miles to km. I did all that, the program runs. However, he has this special way of calling the program: The program's usage options are based on the NAME of the BINARY FILE. If the program name is 'km2miles', the program interp...