Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/139.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 编译代码时无法访问对象_C++_Compiler Construction_Compilation_Compiler Errors - Fatal编程技术网

C++ 编译代码时无法访问对象

C++ 编译代码时无法访问对象,c++,compiler-construction,compilation,compiler-errors,C++,Compiler Construction,Compilation,Compiler Errors,我想编译源代码,但编译时出错: 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

我想编译源代码,但编译时出错:

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
#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

代码有什么问题?

假设声明中的类型RigiBool
RigiBool操作符==(const CharArray&)const未在标题“array.h”“chartype.h”中定义。我认为您应该包括包含类型定义的标题,并确保“object.h”也包含在内。

对于头文件使用类类型变量(而不是指针和引用)值的情况,建议包括包含类定义的头文件。否则,一个简单的正向声明就足够了。

假设声明中的类型RigiBool
RigiBool操作符==(const CharArray&)const未在标题“array.h”“chartype.h”中定义。我认为您应该包括包含类型定义的标题,并确保“object.h”也包含在内。

对于头文件使用类类型变量(而不是指针和引用)值的情况,建议包括包含类定义的头文件。否则,一个简单的正向声明就足够了。

很难从少量的信息中说出来,但我假设
RigiBool
RigiObject
的派生类?当您现在在
chararray.h
中引用
RigiBool
时,它必须知道
RigiObject
基类,但是
RigiBool
也需要知道
RigiBool
。因此,如果不知道派生的
RigiBool
,就不能声明基类。如果在
object.h
中向前声明
RigiBool
有助于打破这个循环,那就试试吧。

从这些小信息中很难说,但我会假设
RigiBool
RigioObject
的派生类?当您现在在
chararray.h
中引用
RigiBool
时,它必须知道
RigiObject
基类,但是
RigiBool
也需要知道
RigiBool
。因此,如果不知道派生的
RigiBool
,就不能声明基类。如果在
object.h
中向前声明
RigiBool
有助于打破循环,请尝试。

类型
RigiBool
RigiObject
ObjPtr
在Charray中不可用。h:您需要包括object.h(如果CCHeader.h不可用,则加上其他定义的
RigiBool
)--类似于object.h中的
RigiBool
rigivalse

注意:如果在
RigiObject
中定义虚拟成员函数,则还应声明析构函数
virtual

注意:在
#include
d头中已经有include-guard,不需要在
#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"   
...
//chararray.h
#ifndef CHARARRAYH
#定义字符
#包括“array.h”
#包括“chartype.h”
...
//对象.h
#ifndef对象
#定义对象
#包括
#包括
#包括
#包括
#包括“CCheader.h”
...

类型
RigiBool
RigiObject
ObjPtr
在chararray中不可用。h:您需要在object.h中包含object.h(如果CCHeader.h不包含,则加上任何其他定义的
RigiBool
)-
RigiBool
RigiFalse

注意:如果在
RigiObject
中定义虚拟成员函数,则还应声明析构函数
virtual

注意:在
#include
d头中已经有include-guard,不需要在
#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"   
...
//chararray.h
#ifndef CHARARRAYH
#定义字符
#包括“array.h”
#包括“chartype.h”
...
//对象.h
#ifndef对象
#定义对象
#包括
#包括
#包括
#包括
#包括“CCheader.h”
...

我们在第35行有
类RigioObject{…
我们在第35行有
类RigioObject{…
我在其他相关文件中引用了
对象.h
。我以前试过这个方法。@Afshin-数组是否从
RigioObject
或CCheader派生。h包括chararray.h(可能是间接的)?我在其他相关文件中引用了
object.h
。我以前尝试过这个方法。@Afshin-
Array
是否派生自
RigiObject
或CCheader.h包括chararray.h(可能是间接的)?