c++

Prepared Statement with Select? Possible?

Hello, is it possible to use prepared statements with the SELECT command? I wrote in C++ following code: sqlite3_bind_int(this->ppGetStmt, 1, id); int rc = sqlite3_step(this->ppGetStmt); //sqlite3_result_int(this->ppGetStmt, &value); sqlite3_reset(this->ppGetStmt); The SQL statement looks like following SELECT value FROM test WHER...

Does new[] call default constructor in C++?

When I use new[] to create an array of my classes: int count = 10; A *arr = new A[count]; I see that it calls a default constructor of A count times. As a result arr has count initialized objects of type A. But if I use the same thing to construct an int array: int *arr2 = new int[count]; it is not initialized. All values are somet...

Is there a way to jump into a specific part of code to debug ?

Do I have to go over all the program using F11 and F10 . Can't I just mark where I want to go and start from there ? ...

Rationale behind static const member initialization syntax?

Hi All, I know how to initialize a static member, but I'm wondering, what is the rationale behind the syntax for this? I'd like to be able to just put the value in the class, a la: class A { static const int i = 3; }; I realise this could mean more rebuilding if I change the value since it's a change in the header - but in some cas...

What is near, far and huge pointers?

Can anyone explain me these pointers with a suitable example ... and when these pointers are used? ...

Creating a C++ DLL loadable by Lua

I have a small app that uses Lua linked as dll (not static). I want to load my own c++-written dll via Lua using package.loadlib (libname, funcname). For this purpose I need to export a function that follows the Lua's lua_CFunction protocol. Clearly for that reason I have to incorporate lua.h into my project and use Lua's functions to pa...

How can I implement a 2D skeletal animation system in my game?

Hey. I want to be able to create a system for skeletal animation in my game. I'm using panda3d as my game engine. I'd like to be able to make simple bone structures and skin them with my sprites. I would prefer to do this with straight code and algorithms, but if I have to use a 3D modeler or something, then I can try to (I didn't do a g...

Can lambda functions be templated?

In c++0x is there a way to template a lambda function? Or is it inherently too specific to be templated? I understand that I can define a classic templated class/functor instead but the question is more like : does the language allow templating lambda functions? ...

c++ variadic function: What is the best way to replace?

In my current project there's some variadic functions being used (ellipsis) that are really being used quite ofen. I have to make some impacting changes to the project, so I thought i might as well get rid of these variadics too. The question I have is, how does one best replace these if the number of arguments passed to these are so v...

Suppress output to cout from linked library

I need to link my C++ programs against a couple shared libraries which generate way too much output to std::cout and std::cerr rendering them both useless for my uses. I have access to the C++ source code of these libraries, but cannot modify them. Is there a way to redirect their output to a different stream or suppress it when linked ...

Error when using Google's protobuf

#include <google/protobuf/io/coded_stream.h> namespace google::protobuf::io .... int fd = open("myfile", O_WRONLY); ZeroCopyOutputStream* raw_output = new FileOutputStream(fd); CodedOutputStream* coded_output = new CodedOutputStream(raw_output); The above is following the tutorial here, but when I compile get the following errors: er...

I am creating a program to implement Sieve of Eratosthenes in C++ for Codechef. But i need a way to optimize the program for large inputs (10^9)

#include <iostream> #include<map> using namespace std; map <long long , long long> h; void sieve(long long start,long long size) { long long i,j; for (i=2; i*i <= size; i++) { if (!h[i]) { for(j = i+i; j < size ;j+=i) { h[j] = 1; } } } for (i=2; i<size; i++) { if (!h[...

Inherit from specialized templated base class and call the right method

I.e. I got 2 specialized types of: template <class Type, class Base> struct Instruction {}; to compile-time-select the appropriate type from within a type list. like: template <class Base> struct Instruction<Int2Type<Add_Type>, Base > { void add() {} }; template <class Base> struct Instruction<Int2Type<Mul_Type>, Base > : ...

"new" operator in multiple threads causes Segmentation Fault

This is related to an issue I have been discussing here and here, but as my investigations have led me away from the STL as the potential issue, and towards "new" as my nemisis, I thought it best to start a new thread. To reiterate, I am using an arm-linux cross compiler (version 2.95.2) supplied by the embedded platform vendor. When ...

Different declaration and definition in c++

Hi, I'm a bit hazy on the rules of declarations vs. definitions. I have the following declaration in funcs.h: void sumTotalEnrgyAndClush(Protein &A,Protein &B,double ans[2],double enrgyA[18][18],double enrgyB[18][18]); Notice that ans[2] is before enrgyA and B. In the funcs.cpp file the definition starts like this: void sumTot...

Create linux make/build file

I am moving a C++ project from Windows to Linux and I now need to create a build/make file. I have never created a build/make file before. I also need to include Boost libraries to make it more complicated. It must also be a makefile and I need to learn how to create makefile anyway, so CMake and SCON are out. IDEs are also out because o...

Details on the Microsoft multi-string format.

In some of its API function Microsoft use the "multi-string" format to specify a list of strings. As I understand it, a multi-string is a null-terminated buffer of concatenated null-terminated strings. But this can also be interpreted as a list of strings, separated by a null character and terminated by two null characters. Here comes ...

Is it a good idea to using class as a namespace in Python

I am putting a bunch of related stuff into a class. The main purpose is to organize them into a namespace. class Direction: north = 0 east = 1 south = 2 west = 3 @staticmethod def turn_right(d): return turn_to_the_right @staticmethod def turn_left(d): return turn_to_the_left # defined a short alias because ...

A basic understanding of C++ header files

I have a theory question rather than an error report. I'm a rookie C++ programmer, trying to promote that away Using the VC++ VS2008 compiler I am often finding myself wondering WHY I want to take some actions in header files. For example look at this code block: #include "DrawScene.h" #include "Camera.h" #include "Player.h" #includ...

Simple makefile generation utility?

Does anyone know of a tool that generates a makefile by scanning a directory for source files? It may be naive: no need to detect external dependencies use default compiler/linker settings ...