[C++] ISO C++ forbids declaration of `<class>' with no type?!

Pagina: 1
Acties:

  • ATS
  • Registratie: September 2001
  • Laatst online: 12-02 13:46
Hallo,

Ik heb een vreemd probleem waar ik niet uitkom. Op een een of andere manier
wordt een definitie van een class niet herkend. Hij ziet KConfig niet als
een type, terwijl het dat wel is.... :? Weet iemand hoe ik dit oplos? De
details staan hier onder.

André

details van het probleem
==================

Ik krijg de onderstaande error:
code:
1
2
3
4
5
6
7
8
9
make[1]: Entering directory 
`/home/andre/development/QtE/cumulus-0.0.1/kflog'
g++ -c -pipe -DQWS -fno-exceptions -fno-rtti -Wall -W -O2 
-fno-default-inline -DNO_DEBUG -I../microkde -I../qtcompat -I.. 
-I./guicontrols -I/opt/Qtopia/include -o dataview.o dataview.cpp
In file included from dataview.cpp:21:
../microkde/kglobal.h:12: ISO C++ forbids declaration of `KConfig' with
no type
../microkde/kglobal.h:12: parse error before `*'

De kglobal.h ziet er alsvolgt uit:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#ifndef MINIKDE_KGLOBAL_H
#define MINIKDE_KGLOBAL_H

#include &quot;klocale.h&quot;
#include &quot;kconfig.h&quot;
#include &quot;kiconloader.h&quot;
#include &quot;kstandarddirs.h&quot;

class KGlobal {
  public:
    static KLocale *locale();
    static KConfig *config();  // &lt;--- dit is regel 12
    static KIconLoader *iconLoader();
    static KStandardDirs *dirs();

    static void setAppName( const QString &amp; );

  private:
    static KLocale *mLocale;
    static KConfig *mConfig; &lt;-- dit is regel 20, geeft dezelfde error
    static KIconLoader *mIconLoader;
    static KStandardDirs *mDirs;

    static QString mAppName;
};

#endif

KConfig is gedeclareerd in de file kconfig.h (die zoals je ziet in de
includes staat):
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#ifndef MINIKDE_KCONFIG_H
#define MINIKDE_KCONFIG_H

#include &lt;qstring.h&gt;
#include &lt;qstringlist.h&gt;
#include &lt;qvaluelist.h&gt;
#include &lt;qcolor.h&gt;
#include &lt;qfont.h&gt;
#include &lt;qmap.h&gt;

class KConfig {
  public:
    KConfig( const QString &amp; );
    ~KConfig();
  
    void setGroup( const QString &amp; );
    
    QValueList&lt;int&gt; readIntListEntry( const QString &amp; );
    int readNumEntry( const QString &amp;, int def=0 );
    QString readEntry( const QString &amp;, const QString &amp;def=QString::null );
    QStringList readListEntry( const QString &amp; );
    bool readBoolEntry( const QString &amp;, bool def=false );
    QColor readColorEntry( const QString &amp;, QColor * );
    QFont readFontEntry( const QString &amp;, QFont * );
    
    void writeEntry( const QString &amp;, QValueList&lt;int&gt; );
    void writeEntry( const QString &amp;, int );
    void writeEntry( const QString &amp;, const QString &amp; );
    void writeEntry( const QString &amp;, const QStringList &amp; );
    void writeEntry( const QString &amp;, bool );
    void writeEntry( const QString &amp;, const QColor &amp; );
    void writeEntry( const QString &amp;, const QFont &amp; );
    
    void load();
    void sync();

  private:  
    static QString mGroup;
    
    QString mFileName;
    
    QMap&lt;QString,bool&gt; mBoolMap;
    QMap&lt;QString,QString&gt; mStringMap;
    
    bool mDirty;
};

#endif

Anyone please?!

My opinions may have changed, but not the fact that I am right. -- Ashleigh Brilliant


  • curry684
  • Registratie: Juni 2000
  • Laatst online: 13-08 16:46

curry684

left part of the evil twins

Klinkt als een bah-bah-error van dit type:
code:
1
2
3
4
5
6
// My CPP

class Auto;
class Fiets

#include &lt;myinclude.h&gt;

Zoals je ziet mist hier een puntkomma achter de 2e declaratie, maar dat geeft altijd de vreemdste errors in de include vervolgens van het type dat je noemt. Wat ook kan:
code:
1
2
3
4
5
6
7
8
int MyFunction()
{
for(int i = 0; i != 684; i++) { // &lt;-- ZIE ACCOLADE!!!
  if(Something())           
    return SomethingElse();
}

#include &lt;myinclude.h&gt;

Dit soort 'unterminated brackets' geeft zelfs nog spannender errors met undeclared types en alles.

Mijn advies dus: spit ff je code helemaal terug door alle includes die voor die compiler error langskomen, dus inclusief alle indirecte includes.

Professionele website nodig?


  • The End
  • Registratie: Maart 2000
  • Laatst online: 11:50

The End

!Beginning

Het lijkt mij meer om de constructor te gaan:
KConfig( const QString & );
Er is geen lege constructor. (Wel een beetje vreemd, want het zijn pointers en dat zou geen problemen moeten geven.)

  • curry684
  • Registratie: Juni 2000
  • Laatst online: 13-08 16:46

curry684

left part of the evil twins

Op dinsdag 23 juli 2002 13:59 schreef The End het volgende:
Het lijkt mij meer om de constructor te gaan:
KConfig( const QString & );
Er is geen lege constructor. (Wel een beetje vreemd, want het zijn pointers en dat zou geen problemen moeten geven.)
Om de reden die je zelf al geeft zou dit betekenen dat die compiler rechtstreeks de vullisbak in zou moeten :) Lijkt me een beetje sterk dus.

Voor ATS: probeer eens of het zo werkt met een predeclaration ertussen:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#ifndef MINIKDE_KGLOBAL_H
#define MINIKDE_KGLOBAL_H

class KConfig;     // &lt;----------  Hier dus

#include &quot;klocale.h&quot;
#include &quot;kconfig.h&quot;
#include &quot;kiconloader.h&quot;
#include &quot;kstandarddirs.h&quot;

class KGlobal {
  public:
    static KLocale *locale();
    static KConfig *config();  // &lt;--- dit is regel 12
    static KIconLoader *iconLoader();
    static KStandardDirs *dirs();

    static void setAppName( const QString &amp; );

  private:
    static KLocale *mLocale;
    static KConfig *mConfig; &lt;-- dit is regel 20, geeft dezelfde error
    static KIconLoader *mIconLoader;
    static KStandardDirs *mDirs;

    static QString mAppName;
};

#endif

Als dit wel werkt zit er ergens iets verneukt in de include-volgorde (unieke defines voor de headers?)

Professionele website nodig?


  • MSalters
  • Registratie: Juni 2001
  • Laatst online: 21-08 17:14
Op dinsdag 23 juli 2002 15:13 schreef curry684 het volgende:

[..]

Om de reden die je zelf al geeft zou dit betekenen dat die compiler rechtstreeks de vullisbak in zou moeten :) Lijkt me een beetje sterk dus.

Voor ATS: probeer eens of het zo werkt met een predeclaration ertussen:
Het heet iha een "forward declaration", en ja, alle classes in die Kglobal.h zouden op die manier gedeclareerd moeten worden ipv via de #include. Je krijgt nl. cyclische afhankelijkheden die precies deze symptomen geven. Alleen voor QString moet je een #include doen, en die is makkelijk te fixen door de mAppName in een namespace{ } in de .cpp te zetten ipv er een static member van te maken.

#include's in headers moet je zoveel mogelijk voorkomen.

Man hopes. Genius creates. Ralph Waldo Emerson
Never worry about theory as long as the machinery does what it's supposed to do. R. A. Heinlein


  • curry684
  • Registratie: Juni 2000
  • Laatst online: 13-08 16:46

curry684

left part of the evil twins

Op dinsdag 23 juli 2002 17:43 schreef MSalters het volgende:
Het heet iha een "forward declaration"
Je snapte toch waar ik het over had, de term 'predeclaration' zegt exact hetzelfde en is een stuk minder typwerk (en in mijn kringen iig algemener geaccepteerd dan forward declaration).

Professionele website nodig?

Pagina: 1