c++

Can I do this with class objects ?

class xyz{ ... ... }; while(i<n){ xyz ob; ... ... } Do I need to destroy the earlier object before reallocating memory to it? ...

shared_ptr magic :)

Mr. Lidström and me had an argument :) Mr. Lidström's claim is that a construct shared_ptr<Base> p(new Derived); doesn't require Base to have a virtual destructor. @Daniel: Really? Will the shared_ptr clean up correctly? Could you please in this case demonstrate how that effect could be implemented? – Armen Tsirunyan @Armen: The sh...

What is the strongest encryption to use on protecting text ?

Hello all I need to encrypt text what is the best encryption to use programmatically ? In general I have input file with string that I need to encrypt then read the file in the application Decrypt it for the application flow . with c++ ...

converting string to integer problem in c++

hello, i am getting an problem string ccc="example"; int cc=atoi(csession); it says cannot convert ‘std::string’ to ‘const char*’ for argument ‘1’ to ‘int atoi(const char*)’ do i should convert the string to char array and then apply to atoi or is there is any other way ...

detecting a string charset

hello. i am looking for the best linux library that will let me detect a string charset. any idea ? ...

print call stack in C or C++

Is there any way to dump the call stack in a running process in C or C++ every time a certain function is called? What I have in mind is something like this: void foo() { print_stack_trace(); // foo's body return } Where print_stack_trace works similarly to caller in Perl. Or something like this: int main (void) { //...

How to obtain total available disk space in Posix systems?

Hi! I'm writing a cross-platform application, and I need the total available disk space. For posix systems (Linux and Macos) I'm using statvfs. I created this C++ method: long OSSpecificPosix::getFreeDiskSpace(const char* absoluteFilePath) { struct statvfs buf; if (!statvfs(absoluteFilePath, &buf)) { unsigned long blksize, ...

How can I automatically load DLLs from a subdirectory?

In Visual Studio, you create a .dll project and it creates a .dll and .lib files. You link statically to the .lib, and if the .dll is in the same folder as the .exe, everything works. I suspect that everything would also work if the .dll was in System32 or any other PATH folder (confirm or correct, please). But here's the question: I ...

mingw g++ cant see sdl-config

All works good if I insert sdl-config output manually. How to fix this bug? g++ -O3 -c 'sdl-config --cflags' test.cpp g++.exe: sdl-config --cflags: no such dile or directory ...

How to fix heap corruption in c/c++?

This is a further question for my previous one here. Is there a general solution for this? ...

No deduction in a class template

template<typename T> class A { public: A(T b) : a(b) { } private: T a; }; A object(12); //Why does it give an error? Why can't the type T be deduced from the argument 12 automatically? ...

Malloc in C++ constructor

I have to interface with some C code from C++ class constructor (Intel library) class A{ A{ x = ippiMalloc(); if(x==NULL) ... } } In the constructor malloc function (intel version) is used. If ippiMalloc function do not succeed what is the correct way to handle it. Throw exception? ...

Non-BTree data structure where inserts are done in a sorted manner but i can later remove objects from random places

i want to find an object with O(logN) and also remove with O(log N) - but no go to balanced tree implementation.. any idea's for that? ...

MSVC9.0 bug or misunderstanding of virtual inheritance and friends?

consider the following code: class A { friend class B; friend class C; }; class B: virtual private A { }; class C: private B { }; int main() { C x; //OK default constructor generated by compiler C y = x; //compiler error: copy-constructor unavailable in C y = x; //compiler error: assignment operator unavailable in...

Detecting if type is a function.

template<class T> struct IsFunc { typedef char one; typedef struct { char dummy_[2]; } two; static one f(...); static two f(T (*)[1]); enum {value = (sizeof(f<T>(0)) == 1)}; }; And if I try to run it in main: void functionA(); int _tmain(int argc, _TCHAR* argv[]) { int a = 0; ...

Prevent child process from system calls

I want to create a child process that call another program (with C++ in Unix). But I want to restrict the child process not to call system(), fopen(), etc. (if it did, it would be terminated). How to do that? ...

Create new category section for property when bulding ActiveX component in MFC

Hi everyone. I'm building ActiveX component in MFC. The problem is that all properties automatically added to miscellaneous section. I want to unite some new properties with new category. I haven't found it in any microsoft samples. However in some advanced ActiveX controls like Component One controls there are new categories, so it is...

Generic inheritance in java

In c++ we can write: #include <iostream> class Base1 { public: void test() { std::cout << "Base 1" << std::endl; } }; class Base2 { public: void test() { std::cout << "Base 2" << std::endl; } }; template<class T> class Derived: public T { }; int main() { Derived<Base1> d1; Derived<Base2> d2; d1.test(); d2.test()...

C++ program does not work on some inputs

Hallo I have this assignment to print only alphabets in a C++ string. It works for most input but when [ and ] are present in the input they are printed as well. #include <iostream> #include <string> using namespace std; int main() { string input = "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG]"; for(int i=0;i<input.s...

Asterisk C++ API

Hello I have seen two Asterisk C++ API: * Astxx: Asterisk C++ API and Utility library. a C++ wrapper for Asterisk enabling developers * C++ Asterisk Manager API wrapper. Supports receiving events from the Asterisk server and sending actions to Asterisk. Did somebody try one of these projects? Thanks in advance. ...