Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/tfs/3.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+;+;)调用公共成员_C++ - Fatal编程技术网

C++ 使用**类对象(C+;+;)调用公共成员

C++ 使用**类对象(C+;+;)调用公共成员,c++,C++,我需要给我的公众成员打电话。接受1个参数的构造函数 这就是我的代码的外观: //主要 Intellisense会带出我所有的成员和私人,除了构造器。。 这可能是原因吗 //MyHeader.h class ClassObject { private: const char* cPtr; float theLength; public: ClassObject( const char* ); // Yes its here and saved.. Clas

我需要给我的公众成员打电话。接受1个参数的构造函数

这就是我的代码的外观: //主要

Intellisense会带出我所有的成员和私人,除了构造器。。 这可能是原因吗

//MyHeader.h

class ClassObject
{
    private:
    const char* cPtr;
    float theLength;
public:
    ClassObject( const char* );  // Yes its here and saved..
    ClassObject(); // an appropriate default constructor
    ~ClassObject( );
    char GetThis( );
    char* GetThat( );
}

我假设以下情况,因为从发布的代码中不清楚:

(1) 。ClassObject的定义如下:ClassType*ClassObject[/some value/10]

(2) 。MyHeader.h中的类定义是类类型而不是类对象

在这种情况下,问题在于以下陈述:

ClassObject[wrdCount] = new ClassType[x]
在这里,它创建“x”个类类型对象。我认为这不是你想要的。我猜您想要通过传递const char*作为构造函数参数来构造一个ClassType对象。如果是这样,您应该这样使用它:

ClassObject[wrdCount] = new ClassType(tmpAray);

还请注意,您假设传递的数组的大小。我建议最好使用std::string之类的东西,而不是原始字符数组。

我不完全清楚您在做什么,但您不能像那样显式调用构造函数。如果您有一个名为
ClassObject
的指向a-
ClassType
的指针,则需要执行以下操作来初始化它:

ClassObject[wrdCount] = new ClassType*[x]; // create a new 'row' in the array with x columns
for (int i = 0; i < x; ++i) // initialize each 'column' in the new row
    ClassObject[wrdCount][i] = new ClassType(tmpArray);
ClassObject[wrdCount]=新类类型*[x];//在包含x列的数组中创建新的“行”
for(int i=0;i

考虑到您粘贴的代码,这似乎没有多大意义(因为wrdCount不会更改)。如果没有准确的问题描述,很难说。

您需要使用标识符。以下是:

ClassObject[wrdCount] = new ClassType[x] ;
尝试将
运算符[]
应用于类类型名称。那有什么好处?没有一个尝试:

ClassObject *a = new ClassType[x];
这将创建一个
a
类型的对象,数组的大小为
x
,类型为
Classtype
s。你需要一个数组吗?由你决定。如果您只需要一个变量,请使用:

ClassObject *a = new ClassType;

你能发布这个的全部代码吗?我不明白你怎么会有一个类对象类,并且还使用类对象作为指针。我是否遗漏了什么,或者“if(!isspace(str2[x])| | isspace(str2[x])”这一行的值总是为真的?你问的真的不清楚。你想计算每个单词的出现次数吗?是的,但这是在OP定义ClassObject之前,出于某种原因(我现在想不起来了),我预感这是类指针的typedef。哼!我会更新的。
ClassObject *a = new ClassType[x];
ClassObject *a = new ClassType;