c++

How to learn proper C++?

While reading a long series of really, really interesting threads, I've come to a realization: I don't think I really know C++. I know C, I know classes, I know inheritance, I know templates (& the STL) and I know exceptions. Not C++. To clarify, I've been writing "C++" for more than 5 years now. I know C, and I know that C and C++ s...

sigwait in Linux (Fedora 13) vs OS X

So I'm trying to create a signal handler using pthreads which works on both OS X and Linux. The code below works on OS X but doesn't work on Fedora 13. The application is fairly simple. It spawns a pthread, registers SIGHUP and waits for a signal. After spawning the signal handler I block SIGHUP in the main thread so the signal should o...

KEY_ENTER vs '\n'?

When I'm using PDcurses and I try to have a while loop exit when the enter key is pressed with while(key != KEY_ENTER), the while loop never exits. However, when I try to have the same loop exit with while((char)key != '\n'), it exits successfully whenever I pressed enter. Why does '\n' work and not KEY_ENTER? btw, key is an int and I ...

C++ forward declaration problem

Hi, I have a header file that has some forward declarations but when I include the header file in the implementation file it gets included after the includes for the previous forward declarations and this results in an error like this. error: using typedef-name ‘std::ifstream’ after ‘class’ /usr/include/c++/4.2.1/iosfwd:145: error: ‘st...

GCC doesn't like C++ style casts with spaces

I am porting some C++ code to GCC, and apperantly it isn't happy with C++ style casting when sapces are involved, as in unsigned int(-1), long long(ShortVar) etc... It gives an error: expected primary-expression before 'long'. Is there any way to make peace with GCC without going over each one of those and rewrite in c-style? ...

ld: symbol(s) not found with OpenSSL (libssl)

...

Guidelines to an Iterator Class

Hi, I have a Red Black tree implemented in c++. It supports the functionality of a STL map. Tree nodes contain keys and the values mapped. I want to write an iterator class for this, but I'm stuck with how to do it. Should I make it an inner class of the Tree class? Can anyone give me some guidelines on how to write it + some resources...

Pointers in c/c++

#include <stdio.h> void main() { int p[]={0,1,2,3,4}; int *a[]={p,p+1,p+2,p+3,p+4}; printf("%u %u %u",a,*a,*(*a)); } What *(*a) will print(will it print 0 or it's address)? And if we make array p as static(static int p[]), output gets changed .Why? ...

Friends, templates, overloading <<

I'm trying to use friend functions to overload << and templates to get familiar with templates. I do not know what these compile errors are: Point.cpp:11: error: shadows template parm 'class T' Point.cpp:12: error: declaration of 'const Point<T>& T' for this file #include "Point.h" template <class T> Point<T>::Point() : xCoordinat...

Can redirection of screen output to file change the result of a C++ code?

I am having this very weird behaviour with a C++ code: It gives me different results when running with and without redirecting the screen output to a file (reproducible in cygwin and linux). I mean, if I get the same executable and run it like ./run or run it like ./run >out.log, I get different results! I use std::cout to output to scr...

Why is 'virtual' optional for overridden methods in derived classes?

When a method is declared as virtual in a class, its overrides in derived classes are automatically considered virtual as well, and the C++ language makes this keyword virtual optional in this case: class Base { virtual void f(); }; class Derived : public Base { void f(); // 'virtual' is optional but implied. }; My question is...

C++ program design

How to effectively design a C++ modular program? How to learn? ...

#pragma once Versus #if !defined MYHEADER_INCLUDED_

What are the differences (in performance, usability and functionality) in using #pragma once and #if !defined MYHEADER_INCLUDED_ constructs? Or what is the difference between the two? ...

Output send to printer

How can the output in languages C# and C++ send to printer? ...

display 25 randomnumbers from an array

Hello, I have in C++ an array of 100 elements, so v[1], ... ,v[100] contains numbers. How can i display, 25 random numbers from this array? So i wanna select 25 random positions from this array and display the values.. How can i do this in C++? Thanks! #include <cstdlib> #include <iostream> #include <math.h> #include <stdlib.h> #i...

Preventing multiple process instances on Linux

What is the best way on Linux platform for the process (C++ application) to check its instance is not already running? ...

Using pointers, references, handles to generic datatypes, as generic and flexible as possible

In my application I have lots of different data types, e.g. Car, Bicycle, Person, ... (they're actually other data types, but this is just for the example). Since I also have quite some 'generic' code in my application, and the application was originally written in C, pointers to Car, Bicycle, Person, ... are often passed as void-pointe...

Member is inaccessible from friend class

I have a declaration like this #include "Output/PtPathWriter.h" // class PtPathWriter // I've also tried forward declaring the friend class // leg data is a class designed to hold data for a single leg. class PtPathLeg { friend class PtPathWriter; // doesn't work //friend void PTPathWriter::writeToFile(string fileName, PtPath* ...

Where is the mistake ?

Hi ... i am implementing a simple linked list in c++. I have a mistake and i don't see it :( #include <stdexcept> #include <iostream> struct Node { Node(Node *next, int value): next(next), value(value) { } Node *next; int value; }; class List { Node *first; int len; Node *nthNode(int index); public:...

C++ program crashes at runtime

Hello, I have this simple c++ program #include <cstdlib> #include <iostream> #include <math.h> #include <stdlib.h> #include <time.h> #include <vector> using namespace std; int aleator(int n) { return (rand()%n)+1; } int main() { int r; int indexes[100]={0}; // const int size=100; //int a[size]; std::vector<in...