Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.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++;错误:在';之前应为非限定错误id;(';代币_C++_Arrays_Function_Pointers_Struct - Fatal编程技术网

C++ C++;错误:在';之前应为非限定错误id;(';代币

C++ C++;错误:在';之前应为非限定错误id;(';代币,c++,arrays,function,pointers,struct,C++,Arrays,Function,Pointers,Struct,我想知道我在抛出错误的代码中做错了什么。 (注意,由于外部限制,除了在数组声明期间,不允许使用->和方括号[]) 以下是我的两个结构: struct RentalCar { char make[10]; char model[10]; int year; float price; bool available; }; struct Agency { char name[10]; int zipcode; RentalCar inv

我想知道我在抛出错误的代码中做错了什么。 (注意,由于外部限制,除了在数组声明期间,不允许使用->和方括号[])

以下是我的两个结构:

struct RentalCar
{
    char make[10];
    char model[10];
    int year;
    float price;
    bool available;
};

struct Agency
{
    char name[10];
    int zipcode;
    RentalCar inventory[5];
    RentalCar* myCar = inventory;
};
在我的代码后面,我有以下内容

Agency myAgencies[3];
Agency* myPointer = myAgencies;
当我收到错误时,我会尝试引用以下内容

inFile>>(*myPointer).(*myCar).make;
由于外部条件,我不允许使用以下修复程序:

inFile>>(*myPointer).inventory[0].make;

非常感谢您的帮助!

您的指针取消引用语法不太正确。解决此问题的最简单方法可能是重写

(*myPointer).(*myCar).make
使用箭头操作符:

myPointer->myCar->make

如果您不能使用
->
,那么您可以使用的是使用指针删除并使用数组本身

inFile>>(*myPointer).(*myCar).make;
变成

inFile >> myAgencies[0].inventory[0].make;

啊,我忘了在问题中提到(也是由于外部限制)不允许使用->。(我一定会在我的问题中编辑它!)@GunnerStone你不允许使用基本的内置操作符?@NathanOliver不,我的情况下不允许使用它(很遗憾),否则我不会有这个问题:(这个答案(在现实世界中)行得通如果不是谷歌的限制,@我只会遇到堆栈溢出。我已经用了3年的C++,所以进一步阅读语法并不能帮助我了解语言。我单独问这个问题,是因为它是如何解决语法错误的。我知道你会被触发,你的评论会被另一个问题触发。post…但是括号是受限制的,除了数组声明之外,不允许在任何地方使用…#我很抱歉sad@GunnerStone如果你不断地改变要求,没有人愿意帮助你。就像我一样,我会离开你被教导的任何地方,去其他地方。他们只会对你造成伤害。