c++

C/C++: Bitwise operators on dynamically allocated memory

In C/C++, is there an easy way to apply bitwise operators (specifically left/right shifts) to dynamically allocated memory? For example, let's say I did this: unsigned char * bytes=new unsigned char[3]; bytes[0]=1; bytes[1]=1; bytes[2]=1; I would like a way to do this: bytes>>=2; (then the 'bytes' would have the following values):...

Eye candy in OpenGL

I'm interested in creating realtime visual special effects. I am limited to OpenGL (in particular, computing power of a MacBook Pro). I want to learn more about doing cool UI/special effects (think the "computers/displays" in Iron Man / Avatar). What are good books/resources for this? Thanks! ...

Policy-based template design: How to access certain policies of the class?

I have a class that uses several policies that are templated. It is called Dish in the following example. I store many of these Dishes in a vector (using a pointer to simple base class), but then I'd like to extract and use them. But I don't know their exact types. Here is the code; it's a bit long, but really simple: #include <iostre...

Memory Leaks - STL sets

I am trying to plug up all my memory leaks (which is massive). I am new to STL. I have a class library where I have 3 sets. I am also creating a lot of memory with new in the library class for adding info to the sets... Do I need to deallocate the sets? If so, how? Here is the library.h #pragma once #include <ostream> #include <m...

Pure Virtual Class and Collections (vector?)

Hello, I'm working on a graphics application that is using virtual classes fairly extensively. It has: A picture class, which is essentially a collection of shapes. A shapes class, which is purely virtual and has a few classes that inherit from it: Circle Polygon Rectangle A Figure shape, which is any graphical figure (also virtual...

testing a string to see if a number is present and asigning that value to a variable while skipping all the non-numeric values?

Hi there, given a string say " a 19 b c d 20", how do I test to see if at that particular position on the string there is a number? (not just the character '1' but the whole number '19' and '20'). char s[80]; strcpy(s,"a 19 b c d 20"); int i=0; int num=0; int digit=0; for (i =0;i<strlen(s);i++){ if ((s[i] <= '9') && (s[i] >= '0')){...

Where can I find a good quick reference for learning C after years of C++?

I last used C professionally around 1997 IIRC. I've used a lot of C++ since then. Now, I find I need to use some C again. One thing I'm sure of is that I can't just drop the obvious C++ features (e.g. classes) and expect everything to work. There are various less obvious syntax changes. I just don't remember what they are. Is there a g...

seekg() failing mysteriously

I have a 2884765579 bytes file. This is double checked with this function, that returns that number: size_t GetSize() { const size_t current_position = mFile.tellg(); mFile.seekg(0, std::ios::end); const size_t ret = mFile.tellg(); mFile.seekg(current_position); return ret; } I then do: mFile.se...

Is Unix coded in C or C++ or both?

Many system calls in Unix use overloading and default variables. This concept is absent in C, so Unix is coded in C++ also right? ...

Virtual Classes Segmentation Faults

I'm working on a graphic application. It makes significant use of virtual classes. I'm getting some segmentation faults that I'm having trouble debugging. The primary classes in this application are: Shape (a virtual class) Rectangle Polygon Circle Picture (essentially a collection of shapes) Here is a shortened copy of the applic...

How do CLang 'blocks' work?

http://clang.llvm.org/docs/BlockLanguageSpec.txt Looks really cool. However, I don't understand it. I don't see examples it. I don't see examples of ideas hard to express in C++ as is, but trivial to express in blocks. Can anyone enlighten me on this? Thanks! ...

linker error - linker input file unused because linking not done. then undefined reference to a function in that file

Ok so I'm having trouble with my linking of files. Basically, my program works: the main program, is gen1 gen1 - recieves input sends to str2value for processing, outputs resaults str2value, brakes input into tokens using "tokenizer" deterines what sort of processing to do to each token, and passes them off to str2num, or str2cmd. then r...

Using openCV staticly on Snow Leoaprd

I am using snow leopard and I am trying to build my app with static libraries... I was able to build opencv with static libraries by changing build_shared_libs to "no" This generated a bunch of .a files (including pch_dephelp.a" files) First off, I don't know what pch_dephelp.a files are (e.g. libcv_pch_dephelp.a) When I tried to com...

Given N points in a 3D space, how to find the smallest sphere that contains these N points?

Given N points in a 3D space, how to find the smallest sphere that contains these N points? ...

How to navigate through a vector using iterators? (C++)

The goal is to access the "nth" element of a vector of strings instead of the [] operator or the "at" method. From what I understand, iterators can be used to navigate through containers, but I've never used iterators before, and what I'm reading is confusing. If anyone could give me some information on how to achieve this, I would appr...

std string problem with libcurl - c++

I'm pretty new to c++ and I'm using libcurl to make an http request and get back a string with the respond's content. size_t write_to_string(void *ptr, size_t size, size_t count, void *stream) { ((std::string*)stream)->append((char*)ptr, 0, size*count); return size*count; } int main(void) { CURL *curl; CURLcode res; ...

c++ function overload resolution regarding templated type and class hierarchy

A templated function gives me the convenience to operate on a variety of types: template<typename T> void destroy(T* obj) { delete obj; } But at some point I want to do some specialization on a class hierarchy: class Base { virtual void doSomething(); }; class Derived : public Base {}; void destroy(Base* obj) { obj->doSomethi...

Passing non-Global C++ objects to Lua functions (Swig)

I am extending an interface with lua, and I've run into a problem in that I would need to pass pointers to objects to the lua code to work upon. These classes will have been wrapped via SWIG, and I could instantiate them via lua using swig, but that would leave me with useless objects. I need to be able to pass a callback object to lua,...

Pointer incrementing query

I have been looking at this piece of code, and it is not doing what I expect. I have 3 globals. int x, y, *pointer, z; Inside of main I declare them. x = 10; y = 25; pointer = &x; now at this point &x is 0x004A144 &y is 0x004A138 pointer is pointing to 0x004A144 Now when I increment: y = *++pointer; it points to 0x004...

C++: having trouble linking from command line

Just getting started with C++ here. I am working on OSX with Eclipse CDT. I have a project with some custom classes and two files "Test.hpp" and "Test.cpp" - the later with my main() method that runs some tests that I have defined and implemented in these two files. I can compile and run from Eclipse with no problems, but when I try to ...