2012-05-29 74 views
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 

这里,我们的两个文件。 object.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 

有什么不好的代码?

+0

哪一行是35行? –

+0

我们在第35行有'class RigiObject {...' –

回答

1

类型RigiBoolRigiObjectObjPtr不可在chararray.h:你需要包括object.h(加任何其他定义RigiBool如果CCHeader.h没有) - 同样,对于RigiBoolRigiFalseobject.h

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

:如果你定义虚拟成员函数在RigiObject蒸发散,你应该声明析构函数virtual以及

:你已经有包括警卫#include d头,没有必要把自己身边的#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" 
... 
+0

我在其他相关文件中引用了'object.h'。我之前尝试过。 –

+0

@Ashshin - 从'RigiObject'或_CCheader.h_包含_chararray.h_(可能间接)派生​​的数组? – Attila

2

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

1

很难说从小的信息,但我会假设RigiBool是派生类RigiObject?当你现在参考RigiBoolchararray.h它必须知道RigiObject基类,但RigiObject也需要知道约RigiBool。所以你不能在不知道派生的RigiBool的情况下声明基类。如果转发宣告RigiBoolobject.h有助于打破周期,请尝试尝试。