C++ is a real pain in the ass. Consider the following code, which is a real-world example (from one of my homeworks) :
globals.h :
#ifndef GLOBALS_H_INCLUDED
#define GLOBALS_H_INCLUDED
#include <pthread.h>
#include "sortie.h"
#include "source.h"
class globals {
public:
static pthread_mutex_t mutexSource; // Sert a eviter que deux threads essayent d'acceder a la source en meme temps
static pthread_cond_t condSourcePleine; // Sert a ce que la source puisse attendre lorsque la file est pleine.
static pthread_cond_t condSourceVide; // Sert a ce que les ordinateurs puissent attendre lorsque la file est vide.
static int nombreSorties; // Indique le nombre total de sorties disponibles. Inferieur a MAXSORTIES.
static sortie **sorties; // Tableau des sorties
static source* src; // Pointeur vers la source
}
#endif // GLOBALS_H_INCLUDED
This code doesn't compile; g++ says on line 3 of globals.cpp : expected initializer before 'globals'. Wow, how helpful. I can google that error message for 2 hours and not get any kind of relevant information.
First, just to get those static public variables to both compile and link properly, I have to re-state their existence in a separate cpp file, and yeah, that was from googling, there's no way I ever could've guessed that.
But anyway, as it turned out after 15 minutes of staring blankly at that perfect-looking code, I discovered I was missing a ';' after the class declaration. What? It's 2009 and my compiler can't tell me I'm missing a ****ing semicolon.
OMG. :angry:
Sometimes I feel genuinely stupid after discovering a mistake such as forgetting a '&' when I'm passing an address or things of that nature, but here I just feel like C++ has utterly wasted 15 minutes of my time.
Question
Andre S. Veteran
C++ is a real pain in the ass. Consider the following code, which is a real-world example (from one of my homeworks) :
globals.h :
#ifndef GLOBALS_H_INCLUDED #define GLOBALS_H_INCLUDED #include <pthread.h> #include "sortie.h" #include "source.h" class globals { public: static pthread_mutex_t mutexSource; // Sert a eviter que deux threads essayent d'acceder a la source en meme temps static pthread_cond_t condSourcePleine; // Sert a ce que la source puisse attendre lorsque la file est pleine. static pthread_cond_t condSourceVide; // Sert a ce que les ordinateurs puissent attendre lorsque la file est vide. static int nombreSorties; // Indique le nombre total de sorties disponibles. Inferieur a MAXSORTIES. static sortie **sorties; // Tableau des sorties static source* src; // Pointeur vers la source } #endif // GLOBALS_H_INCLUDEDglobals.cpp :
This code doesn't compile; g++ says on line 3 of globals.cpp : expected initializer before 'globals'. Wow, how helpful. I can google that error message for 2 hours and not get any kind of relevant information.
First, just to get those static public variables to both compile and link properly, I have to re-state their existence in a separate cpp file, and yeah, that was from googling, there's no way I ever could've guessed that.
But anyway, as it turned out after 15 minutes of staring blankly at that perfect-looking code, I discovered I was missing a ';' after the class declaration. What? It's 2009 and my compiler can't tell me I'm missing a ****ing semicolon.
OMG. :angry:
Sometimes I feel genuinely stupid after discovering a mistake such as forgetting a '&' when I'm passing an address or things of that nature, but here I just feel like C++ has utterly wasted 15 minutes of my time.
Thanks for allowing to vent, it feels good.
Edited by Dr_AsikLink to comment
Share on other sites
10 answers to this question
Recommended Posts