c++

How does BLAS get such extreme performance?

Out of curiosity I decided to benchmark my own matrix multiplication function versus the BLAS implementation... I was to say the least surprised at the result: Custom Implementation, 10 trials of 1000x1000 matrix multiplication: Took: 15.76542 seconds. BLAS Implementation, 10 trials of 1000x1000 matrix multiplication: Too...

including header files in Dev C++

Hi i'm new here and learning C++ ive just created 2 very simple files , one hpp, and one cpp.. They are located in the same directory and I've added the directory to the C++ includes list through the 'Tools > Compiler Options' window. using the command #include "Cat.hpp" i get the following error 5 K:- C++ Excercises\Cat.cpp In ...

derive problem about c++

Why I can't access base class A's a member in class B initialization list? class A { public: explicit A(int a1):a(a1) { } explicit A() { } public: int a; public: virtual int GetA() { return a; } }; class B : public A ...

Properties editor design pattern?

Warning: This is super in-depth. I understand if you don't even want to read this, this is mostly for me to sort out my thought process. Okay, so here's what I'm trying to do. I've got these objects: When you click on one (or select several) it should display their properties on the right (as shown). When you edit said properties it ...

Performance difference between ++iterator and iterator++ ?

My workmate claims that for object types preincrement is more efficient than post increment e.g. std::vector<std::string> vec; ... insert a whole bunch of strings into vec ... // iterate over and do stuff with vec. Is this more efficient than the next // loop? std::vector<std::string>::iterator it; for (it = vec.begin(); it != vec....

No Appropriate Default Constructor For Node struct (C++ Syntax)

No error // list.h //... list::node::node(const winery node *new_node = new node( winery ); } Adding the list::node::node(const winery &winery ) function to the list.cpp file enables allocation of the node. however, it forces me to add a dfault constructor to the winery class: class winery { public : winery(const char * c...

C++ compiler warning - returning local variable

I'm simply trying to overload a + operator and I'm getting this compiler warning reference to local variable 'tmp' returned Here is the code for the overload const Int& Int::operator+(const Int& p) const { Int tmp = value + p.value; return tmp; } Here is the class class Int{ int value; public: Int() {} // defaul...

Create a SOCKS Proxy that does nothing special

I am trying to create a SOCKS proxy in C++ that runs as a background process on localhost. If the user's browser is configured to use the proxy, I want all HTTP requests to be passed along through the normal TCP/IP stack. i.e. The browser will behave exactly as it normally would. Eventually I will add another layer which will check to ...

Pre-allocate space for C++ STL queue

I'm writing a radix sort algorithm using queues and I would like to have a STL queue allocate space before I start adding things to the queue so that I can avoid constant dynamic resizing operations. Even though this doesn't exist, I want something with the effect of... queue<int> qs(N); for(int i=0;i<N;++i) qs.push(rand()); in su...

Access member function of another .cpp within same source file?

I am working in Visual C++. I have two .cpp files in the same source file. How can I access another class (.cpp) function in this main .cpp? ...

C++ Constant Expression and Array Bounds

Can someone please explain (what might be my perceived) disparity in errors in the following code? Essentially why are "//OK" okay and "//error" errors? (Compiler is i686-apple-darwin9-g++-4.0.1 (GCC) 4.0.1 (Apple Inc. build 5490)) #include <cmath> #include <iosfwd> template <typename T> class TT{ char _c[sizeof(T) + static_cast<si...

How to strip debug code during compile time in C++?

Say I have a C++ function debugPrint(int foo). How can I most conveniently strip that from release builds? I do not want to surround every call to debugPrint with #ifdefs as it would be really time consuming. On the other hand, I want to be 100% sure that the compiler strips all the calls to that function, and the function itself from re...

How to convert a vector<pair<int,int> > to multimap<int,int> efficiently?

How to convert a multimap<int,int> to vector<pair<int,int> > efficiently EDIT: Sorry for the trouble I was actually looking for converting vector to map ...

access two .cpp file within same source file in vc++

Possible Duplicate: main.cpp access member function of another .cpp witin same source file i use two cpp files within same sourcefile another.cpp here i use one class and member function like , Another.cpp class A { public : int Add(); }; int A::Add() { ----- ------- } ---------------...

Object slicing with private copy constructor in derived class in C++

Hi all Suppose I have something like the following in test.cxx (and that I do the object slicing at 1 intentionally): class A { }; class B : public A { // prevent copy construction and assignment B(const B& other); B& operator=(const B& other); public: explicit B(){} }; class C { A m_a; public: explicit C() : m_a( B() ) {...

template function specialization problem

Hello! I am using templates to implement a range checked conversion from int to enum. It looks like this: template<typename E> E enum_cast(const int &source); The template function placed more or less in the root-directoy of the project. When defining a new enum that is foreseen to be assigned values from a config file like this: en...

vector of vectors, bad alloc [c++]

Hi, I've a class named Contact and I want to build a data structure of pointers to those objects like a matrix of 127 rows and 20 columns. I've tried to use the std::vector class in this way std::vector < std::vector<Contact* > > matrix (127, std::vector < Contact* > (20)); then, having declarated the following in the header std::ve...

reinterpret_cast to void* not working with function pointers

I want to reinterpret cast a function pointer into a void* variable. The type of the function pointer will be of type Class* (*)(void*). Below is the sample code, class Test { int a; }; int main() { Test* *p(void **a); void *f=reinterpret_cast<void*>(p); } The above code works well with Visual Studio/x86 compilers. B...

How is *array* memory allocated and freed in C and C++?

My question specifically is in regards to arrays, not objects. There a few questions on SO about malloc()/free() versus new/delete, but all of them focus on the differences in how they are used. I understand how they are used, but I don't understand what underlying differences cause the differences in usage. I often hear C programmers...

C and C++: Freeing PART of an allocated pointer.

Let's say I have a pointer allocated to hold 4096 bytes. How would one deallocate the last 1024 bytes in C? What about in C++? What if, instead, I wanted to deallocate the first 1024 bytes, and keep the rest (in both languages)? What about deallocating from the middle (it seems to me that this would require splitting it into two poin...