0

我想编译Rigi源代码,但编译时出现一些错误:

adt/object.h: At global scope:
adt/object.h:35:18: error: ‘class RigiObject RigiObject::RigiObject’ is inaccessible
adt/chararray.h:51:13: error: within this context
make: *** [cl_arcflags.o] Error 1

这是我们的两个文件。 对象.h

#ifndef OBJECTH
#define OBJECTH 1

#include <stdio.h>
#ifndef STREAM_H
#include <iostream>
#endif
#ifndef __STRING_H
#include <string.h>
#endif
#ifndef __STDLIB_H
#include <stdlib.h>
#endif
#ifndef _CCHEADER_H_
#include "CCheader.h"
#endif

extern char* indent_line(int);

class RigiObject;
typedef RigiObject* ObjectPtr;

#define Oberr(a) fprintf(stderr,"ERROR :: Generic Object Routine Called :: %s\n","a");

class RigiObject {
    public:
    RigiObject() {/*Oberr(RigiObject)*/;}
    ~RigiObject() {/*Oberr(~RigiObject)*/;}  

    // Routines that are really described by the Derived Classes
    virtual int Printout(int)  const
      {Oberr(printout); return (int) 0;}
    virtual unsigned int Hash() const  
      {Oberr(hash); return (unsigned int) 0; }
    virtual RigiBool isEqual(void* a) const
      {Oberr(isEqual); a = NIL; 
           (void) abort();
       return (RigiBool) RigiFalse;}  
    virtual void Delete_class(ObjectPtr) 
      {Oberr(delete_type);}
    virtual void* Create_class();
    virtual void* Duplicate_class();

};

#endif

chararray.h

#ifndef CHARARRAYH
#define CHARARRAYH

#ifndef ARRAYOBIDH
#include "array.h"
#endif
#ifndef CHARTYPEH
#include "chartype.h"
#endif

class CharArray;
typedef CharArray* CharArrayPtr;

class CharArray : public Array {
    int slot;
    public:
   // Routines to initialize and destroy the class.
    CharArray(unsigned int size = CLTN_DEFAULT_CAPACITY);
    CharArray(const CharArray&);
    ~CharArray(); 

    // Functions that are Required to Use this Class as an Object

        // .... all routines the same as in Class Array.......

   // Routines that are required by a Collection class and derived classes
   // of Collections. [See Array Class for these routines.]

    virtual unsigned int size() const {return slot;}

        // .... all routines the same as in Class Array.......

   // Routines specific to this class
    void operator=(const CharArray&);
    RigiBool operator==(const CharArray&) const;
    void Create(char*);
    void Create(char*,int);
    void Create(int, char*);
    void Add(char*);
    void Add(CharType&);
    void Addob(RigiObject& ob)  
        {Array::Add(slot++,&ob);}
    void Append(char*);
    char* Concat(char);
    int FindIndex(char*);
    char* Remove() 
        {return ((CharTypePtr)Array::Remove(--slot))->string();}
    ObjectPtr Pop()
        {return (Array::Remove(--slot));}
    ObjectPtr Look(int i)
        {return (Array::At(i));}
    void Empty();
    virtual unsigned int Size() const
        {return slot;}
    char* Peek();
    char* At(int);
};

#endif

代码有什么问题?

4

3 回答 3

2

假设声明中的类型 RigiBoolRigiBool operator==(const CharArray&) const;未在标题“array.h”“chartype.h”之一中定义,我认为您应该包含包含类型定义的标题,并且只是为了确保“object.h”也。对于头文件使用类类型变量值(不是指针和引用)的情况,建议包含包含类定义的头文件。否则一个简单的前向声明就足够了。

于 2012-05-29T19:27:04.377 回答
1

从很少的信息中很难说,但我认为RigiBool它是一个派生类RigiObject?当你现在引用它时RigiBoolchararray.h它必须知道RigiObject基类,但RigiObject也需要知道RigiBool. 所以你不能在不知道派生的情况下声明基类RigiBool。尝试前向声明是否RigiBool有助于object.h打破循环。

于 2012-06-21T09:19:54.093 回答
1

chararray.h中不提供类型RigiBool,RigiObject_ _ _ _ _ _ _ObjPtrRigiBoolRigiBoolRigiFalse

// somewhere at the top of chararray.h
#include "object.h"

注意:如果你定义了虚成员函数RigiObject,你也应该声明析构函数virtual

注意:您已经d 标头中包含保护,#include无需将它们放在#include指令周围 - 否则表明(在您的情况下错误地)您正在进行条件编译

//chararray.h
#ifndef CHARARRAYH  
#define CHARARRAYH  

#include "array.h"  
#include "chartype.h"  
...

//object.h
#ifndef OBJECTH   
#define OBJECTH

#include <stdio.h>   
#include <iostream>   
#include <string.h>   
#include <stdlib.h>   
#include "CCheader.h"   
...
于 2012-06-21T10:23:05.323 回答