c++ compiler



  • ich hab gestern ausversehen in falschen forum mein problem geschrieben sry.
    hab das aber auch ausprobiert mit dem class matrix hat aber nicht funktioniert.

    sry mit meinem beitrag, kenne mich mit foren nicht sogut aus.

    EDIT:
    wie mache ich das mit diesen CPP-tags


  • Mod

    Eine friend-Deklaration (allein) macht den Namen nicht im umliegenden Namensraum sichtbar, und das ürfte ohne Weiteres etwas sein, was durch ältere Compiler nicht richtig umgesetzt wird (ich bin ziemlich sicher, dass es in prä-Standard C++ anders war).
    Die Klasse matrix muss folglich im Namensraum deklariert werden, bevor die Deklaration des entsprechenden Konstruktors erfolgt. Ob die friend-Deklaration damit überflüssig wird (weil von den friend-Privilegien kein Gebrauch gemacht wird), ist aus dem gezeigten Code nicht erkennbar.
    Es muss also die Deklaration

    class matrix;
    

    vor der Klassendefinition eingefügt werden (das würde im Übrigen den alten Compiler nicht stören).



  • ok danke!



  • Hätte da noch eine Frage, wie gesagt bin ziemlich neu auf dem Gebiet und würde mich über jede Hilfe freuen.

    Der Code sieht folgends aus:

    #ifndef _strings_
    #define _strings_
    
    #include <iostream> 
    class stringc {		// in allen Dateien string in stringc umbenannt
      char *s;
      int   l;
      char *sep;
      char *tk;
      int   tp;
    public:
      stringc substr(int pos, int len);
      stringc substr(int pos, int len) const { return ((stringc)*this).substr(pos, len); };
      int search(int, int, const char*, int = -1) const;
      int search(int, int, char) const;
      long double toDouble(bool ns = false) const;
      int toDoubleLength(bool ns = false) const;
    public:
      stringc();
      stringc(const char);
      stringc(const char *);
      stringc(const stringc &);
      ~stringc();
    
      stringc& operator=(const char);
      stringc& operator=(const char *);
      stringc& operator=(const stringc &);
    
      friend stringc operator+(const stringc &, const stringc &);
    
      stringc& operator+=(char);
      stringc& operator+=(const char *);
      stringc& operator+=(const stringc &);
    
      char& operator[](int i);
      const char& operator[](int i) const;
    
      friend const char *pointer(const stringc &a) { return(a.s); };
    
      friend std::ostream& operator<<(std::ostream&, const stringc &);
      friend std::istream& operator>>(std::istream&, stringc &);
    
      friend operator==(const stringc &x, const char *s);
      friend operator==(const stringc &x, const stringc &y);
      friend operator!=(const stringc &x, const char *s);
      friend operator!=(const stringc &x, const stringc &y);
    
      friend stringc upcase(const stringc &);
      friend stringc downcase(const stringc &);
      int length() const { return(l); };
    
      friend stringc str(const double v);
      friend stringc spstr(const double v);
      friend long double sval(const stringc &s) { return s.toDouble(true); };
      friend int svallen(const stringc &s) { return s.toDoubleLength(true); };
      friend long double val(const stringc &s) { return s.toDouble(); };
      friend int vallen(const stringc &s) { return s.toDoubleLength(); };
    
      stringc token();
      int token(const stringc &s);
      int next();
    
      int index(char c, int startpos = 0) const    
        { return search(startpos, l, c); };
      int index(const stringc& y, int startpos = 0) const     
        { return search(startpos, l, y.s, y.l); };
      int index(const char* t, int startpos = 0) const 
        { return search(startpos, l, t); };
      int contains(const stringc &x) const
        { return(index(x) >= 0); };
    
      stringc at(int pos, int len)    { return(substr(pos,len)); };
      stringc before(int pos)         { return(substr(0,pos)); };
      stringc before(const stringc &x) { return(substr(0,index(x))); };
      stringc before(const stringc &x) const { return(substr(0,index(x))); };
      stringc after(int pos)          { return(substr(pos+1,l-pos)); };
      stringc after(const stringc &x)  
        { int p = index(x); return(substr(p+x.l, l-p-x.l)); };
      stringc through(const stringc &x)
        { return(substr(0,index(x)+x.l)); };
      stringc from(const stringc &x)
        { int p = index(x); return(substr(p, l-p)); };
    
      void error(const char *) const;
    };
    
    #endif
    

    und die Fehlermeldung dazu ist folgends

    strings.h:44: error: ISO C++ forbids declaration of 'operator==' with no type
    strings.h:45: error: ISO C++ forbids declaration of 'operator==' with no type
    strings.h:46: error: ISO C++ forbids declaration of 'operator!=' with no type
    strings.h:47: error: ISO C++ forbids declaration of 'operator!=' with no type
    

    Ich danke schon im Vorauss



  • bool



  • d.h. es wird erwartet das auf beiden seiten typ boolean ist oder verstehe ich das falsch



  • rückgabetyp



  • hmm sry verstehe leider nicht was muss ich da machen, das was in klammern steht zum typ bool machen?



  • [friend] <rückgabetyp> operator==(<parameterliste>);



  • bladeexx schrieb:

    hmm sry verstehe leider nicht was muss ich da machen, das was in klammern steht zum typ bool machen?

    Grundsätzlich ist friend kein Rückgabewert, und alle Funktionen erfordern unter C++ einen solchen. Manche Compiler sind was den Standard angeht hier lasch und geben dann nur eine Warnung (und nehmen int als Rückgabe an). Und auch ein operator ist eine Funktion.

    Wenn du alten Code hast solltest du zudem auf "new" Acht geben. Früher gab new im Fehlerfall 0 zurück, heute eine Exception.

    cu André



  • um das problem zu lösen muss ich nach dem friend "bool" schreiben, oder das friend in klammern von bool ?



  • was meinst du mit new? gibt es eine kompiler einstellung wo man das einstellen kann?



  • bladeexx schrieb:

    um das problem zu lösen muss ich nach dem friend "bool" schreiben, oder das friend in klammern von bool ?

    beispiel



  • Lern doch erstmal die C++-Grundlagen. Alles was hier genannt wurde, gehört zum Basiswissen einem C++ler, der schon mal ein C++-Einsteigerbuch durchgearbeitet hat. Zumindest ein solches Buch sollte man besitzen, um jetzt nach den genannten Stichworten nachzuschlagen.



  • ok danke für eure mühe, werde mich in die grundlagen stürzen


Anmelden zum Antworten