c++

Templated class function T: How to find out if T is a pointer?

As a follow-up to this question: I need to decide in a class function like this: template< typename T > bool Class::Fun <T*> ( T& variable ) {...} whether T is a pointer or not. In the question cited above the answer was to use partial template specialization. As far as I've found out this is not possible for class functions. Is this...

Find largest and second largest element in a range

How do I find the above without removing the largest element and searching again? Is there a more efficient way to do this? It does not matter if the these elements are duplicates. ...

Basic doubt in QT using C++ about making objects...

int main (int argc, char* argv[]) { QApplication app(argc, argv); QTextStream cout(stdout, QIODevice::WriteOnly); // Declarations of variables int answer = 0; do { // local variables to the loop: int factArg = 0; int fact(1); factArg = QInputDialog::getInteger(0, "Factorial C...

Partial specialization of a class template in derived class affects base class

I have a metafunction: struct METAFUNCION { template<class T> struct apply { typedef T type; }; }; Then I define a helper: template<class T1, class T2> struct HELPER { }; And then I have second metafunction which derives from the METAFUNCTION above and defines partial specialization of apply struct: struct METAFUNCION2...

What is "strip" (GCC application) used for?

Hi, what is this little application for? When using it without any options reduces the size of the executables, but how/what it does? ...

Deterministic handle allocation algorithm

I'm trying to find an efficient deterministic way of allocating a 32-bit handle in such a way that it will operate indefinitely. A simple incrementing counter will not work because it will eventually loop around. Extending to 64-bits isn't possible because the values will be used in a network protocol which is expecting a 32-bit value. ...

const char* to LPTSTR

I am trying to call a function that accepts an LPTSTR as a parameter. I am calling it with a string literal, as in foo("bar"); I get an error that I "cannot convert parameter 1 from 'const char [3]' to 'LPTSTR'", but I have no idea why or how to fix it. Any help would be great. ...

execl pipe without dup

Hello everyone, I am trying to execute a program from a parent using execl. I do the normal pipe setup and fork. Here is the trick... I need my children (there can be an arbitrary number of children) to all communicate with the parent. Program "A" (parent) creates pipe forks and execl into "B" (child). In the main() function of prog...

Read a password from std::cin

I need to read a password from standard input and wanted std::cin not to echo the characters typed by the user... How can I disable the echo from std::cin? here is the code that I'm currently using: string passwd; cout << "Enter the password: "; getline( cin, passwd ); Edit: I'm looking for a OS agnostic way to do this. Here there a...

Where to get peer review of code and how to get my code attention?

I'm just now learning to programming at age 17. It's hard for me to talk to other programmers as I'm just out of high school (which means I can't take programming courses). I know that I write terrible code, and not like Jeff Atwood terrible code, my code actually sucks. So where can I post some of my code and get real programmers to rev...

pthread in a class

Hey everyone, considering the following code (compiled with g++ -lpthread thread_test.cpp) how can I know what number thread I am in from inside "thread_function"? And let me know if you have any other suggestions. Thanks! thread_test.cpp: #include <stdio.h> #include <stdlib.h> #include <pthread.h> #include <unistd.h> class A { p...

Ambiguous template, Code Warrior

The following code compiles in Visual C++ and gcc, but fails with Code Warrior The complaint is that the call to the template is ambiguous -- can't decide between doIt( M* ) and doIt( M const* ), even though in each case, the parameter is unambiguously cost or non-const. Irritatingly, if I supply the second template argument, it decides...

Most portable JIT compiler library?

I'm looking for the most portable JIT compiler library, like asmjit or jitasm. When I say 'most portable' I mean, that has the most support for a wide verity of architectures. Language doesn't matter so much, but C++ would be the best solution, especially when coupled with GCC. Important architectures for me, are x86/64, PowerPC and AR...

Help with boost bind/functions

Hi, I have this function signature I have to match typedef int (*lua_CFunction) (lua_State *L);//target sig Here's what I have so far: //somewhere else... ... registerFunction<LuaEngine>("testFunc", &LuaEngine::testFunc, this); ... //0 arg callback void funcCallback0(boost::function<void ()> func, lua_State *state)...

[WEB-CGI-C++] I want to start developing CGI, but I am very new at this.

Hi I want to develop my next web project in C++ as FastCGI but I don't know how to start and google wasn't very friendly about this. I really don't know much about fastCGI or others libraries that makes cgi persistent... Tried to read some stuff, but it seems to be used along Linux with all those .configure Makefiles etc... can anyone ...

How does boost implements signals and slots?

To continue another question, lets ask this: How does Boost implement the signals/slot mechanism? See: http://stackoverflow.com/questions/1406940/how-signal-and-slots-are-implemented-under-the-hood http://www.boost.org/doc/libs/1%5F40%5F0/doc/html/signals.html ...

Calling constructor from another class

If I have a class like this: typedef union { __m128 quad; float numbers[4]; } Data class foo { public: foo() : m_Data() {} Data m_Data; }; and a class like this: class bar { public: bar() : m_Data() {} foo m_Data; } is foo's constructor called when making an instance of bar? Because when I try to use bar's m_Data...

Is it ok to use wcout to print char* ?

Consider this line: std::wcout << "Hello World!"; Is it OK to pass char* or char to wide stream? ...

Reading and checking Character Problem

This is my code #include<stdio.h> int main() { char choice; printf("Do you want to enter a number:"); scanf("%c",&choice); while(choice == 'y') { printf("Entered number\n"); printf("Do you want to enter a number:"); scanf("%c",&choice); } printf("End\n"); return 0; } and the output...

How to hide "Cancel" button in QInputDialog in QT using C++?

#include<QtGui> int main (int argc, char* argv[]) { QApplication app(argc, argv); QTextStream cout(stdout, QIODevice::WriteOnly); // Declarations of variables int answer = 0; do { // local variables to the loop: int factArg = 0; int fact(1); factArg = QInputDialog::getInteger(0, "Factorial Calculator"...