Skip to main content
gamedev.net
🔒 Locked

simple c++ question

Started by yves032784 Apr 30, 2004 at 12:56 PM 4 replies 1.1k views
Original Post
yves032784
yves032784
it's been a while since i've done any coding (1 year and a half), and i need some help. For some reason when i put my declerations in a .h file I get tons of errors. Here is my code P.S.: everything was ok when it was just one egui.cpp file, thins went wrong only after i put in the class decleration in the egui.h file this is the "egui.h" file
#ifndef EGUI_H
#define EGUI_H

#include <qmainwindow.h>
#include <qapplication.h>

class EWidget : public QWidget
{
public:
    EWidget( QWidget *parent=0, const char *name=0 );
};


#endif
    
and this is the "egui.cpp" file:
EWidget::EWidget( QWidget *parent, const char *name ): QWidget( parent, name )
{
    setMinimumSize( 200, 300 );
    setMaximumSize( 400, 500 );

    QPushButton *viewPackages=new QPushButton("View  packages for selected category", this, "viewPackages");
    viewPackages->setGeometry(10, 11, 240, 50 );
    
 
    QComboBox *categorySelectComboBox=new QComboBox ( this, "categorySelectComboBox" );
    categorySelectComboBox->setGeometry(260, 20, 240, 20);
    //add elements to the combobox
    int numberOfPackages=10;
    QStrList packageNames;
    for(int i=0;iinsertStrList(packageNames,numberOfPackages );
    
    QButtonGroup *packageCategoryGroup=new QButtonGroup("Select a category to view",this,"packageCategoryGroup");
    packageCategoryGroup->setGeometry( 10, 70, 460, 400);
    //inserting radio buttons in the qbuttongroup:
    QRadioButton *radioButton1= new QRadioButton( this, "text" );
    packageCategoryGroup->insert(radioButton1,0);
    
    //QSlider ( QWidget * parent, const char * name = 0 )
    QSlider *packageCategoryGroupSlider=new QSlider(this,"packageCategoryGroupSlider");
    packageCategoryGroupSlider->setGeometry(470, 80, 31, 390);
    
}
    
and these are the errors I get:
*cd /home/yves/programming/emergegui/src && QTDIR="/usr/qt/3" gmake -k egui.o 
*compiling egui.cpp (g++) 
*egui.cpp:22: error: syntax error before `::' token 
*egui.cpp:25: error: ISO C++ forbids declaration of `setMaximumSize' with no type 
*egui.cpp:25: error: initializer list being treated as compound expression 
*egui.cpp:27: error: syntax error before `*' token 
*egui.cpp:28: error: syntax error before `->' token 
*egui.cpp:31: error: syntax error before `*' token 
*egui.cpp:32: error: syntax error before `->' token 
*egui.cpp:35: error: 'QStrList' is used as a type, but is not defined as a type. 
*egui.cpp:36: error: parse error before `for' 
*egui.cpp:36: error: parse error before `;' token 
*egui.cpp:36: error: syntax error before `++' token 
*egui.cpp:38: error: syntax error before `->' token 
*egui.cpp:40: error: syntax error before `*' token 
*egui.cpp:41: error: syntax error before `->' token 
*egui.cpp:43: error: syntax error before `*' token 
*egui.cpp:44: error: syntax error before `->' token 
*egui.cpp:47: error: syntax error before `*' token 
*egui.cpp:48: error: syntax error before `->' token 
**** Exited with status: 2 ***
    
Where did i go wrong? [edited by - yves032784 on April 30, 2004 1:59:46 PM] [edited by - yves032784 on April 30, 2004 2:00:10 PM] [edited by - yves032784 on April 30, 2004 2:02:49 PM]
BriTeg
BriTeg
At top of egui.cpp, add:


#include "egui.h"
Brianmiserere nostri <font color=#BC
WildWest
WildWest
You have to #include your egiud.h file in your egiud.cpp file.

The Wild Wild West - Desperado!
The Wild Wild West - Desperado!
RS_Hybrid
RS_Hybrid
i use to get errors when declared classes like that. the solution that solved my problem was to fix the class declaration like this

//this caused the error
#include "Object2.h"
class Object
{
private:
int a, b;
public:
void setPtr(int id*=0);
void doSomething(Object2 *other=0);

};

//this fixed the error
#include "Object2.h"
class Object
{
private:
int a, b;
public:
void setPtr(int* = 0); //<---removed variable name
void doSomething(Object2 * = 0);<---same here

};

I don''t know if that was self explanatory, hope that helps
no theory`
Sneftel
Sneftel
quote:
Original post by RS_Hybrid
i use to get errors when declared classes like that. the solution that solved my problem was to fix the class declaration like this
(...)


There''s absolutely no functional difference between those two code snippets.


"Sneftel is correct, if rather vulgar." --Flarelocke

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.