From kdevelop Sun Feb 27 11:26:45 2000 From: nobody Date: Sun, 27 Feb 2000 11:26:45 +0000 To: kdevelop Subject: Re: Please help me back on the track! X-MARC-Message: https://marc.info/?l=kdevelop&m=95165080510583 Peter Thorstenson wrote: > > Hi! > > I don't know if this is the prober place to post this. > I'm learning C++ and have been using kdevelop since 2 months. > My application for KDE 1.X is getting along over my expectations. That means > good. > However, five days ago I ran in to a problem that does not let me continue. > When the proble occured I ran kdevelop 1.0 so I changed it to 1.2beta2 > but with no change. > To me it seems like a basic problem probably due to lak of knowelage from my > side. > Any help is appreciated. > > Problem description: > A added a new class to my project: "mp3_header". In this class I declare a > variable "cat" as public. To me this means that any other class should be > able to set or alter the value of this variable. In this function it should > be enough to declare it as private I think. > BUT if I try to alter the value from a menu-slott bu calling "setCat()" as > follows, the program > quits directly with error: > > Program received SIGSEGV, Segmentation fault. > > In the prog.h file: > #include > : > : > private: > mp3_header *header; > > In the prog.cpp file: > //The command I put cleanly in a menu-slot > header->setCat(); > > The functions I make in this class works fine. As long as I do not use any > variables declared outside the functions. Well it's not only this class it's > any class I add that works like this. > The program compiles fine. No complaints about missing declarations or > anything. > To me it seems as the declaration of the variable doesn't work. I must be > missing something very important! > > I've been struggling for five days now trying to solve it but without luck. > PLEASE help me back on the track! > > Regards, > > Peter Torstenson > Rio de Janeiro, 35 degrees Celcius.... > > OK here's the info: > > The class I added: > **** mp3_header.h ******************* > #ifndef MP3_HEADER_H > #define MP3_HEADER_H > > class mp3_header { > public: > mp3_header(); > ~mp3_header(); > int cat; > void setCat(); > }; > > #endif > > **** mp3_header.cpp ****************** > #include "mp3_header.h" > #include > > mp3_header::mp3_header(){ > } > mp3_header::~mp3_header(){ > } > void mp3_header::setCat(){ > cat=2; //This is where it stops!! > // Saying: Program received SIGSEGV, Segmentation fault. > > } > **************************************** > Debug info: > > MEMORY: > 0x0: Cannot access memory at address 0x0. ^^^ Do you allocate memory for this variable (via new)? The variable *header is declared as a pointer. Use something as: header = new mp3_header(); header->setCat(); -- Jarda What do you want to hack today?