C ++需要有关对象数组的帮助 [英] C++ Need help with array of objects

查看:57
本文介绍了C ++需要有关对象数组的帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好!


我有点陷入困境,我需要创建一个对象数组(类)并且似乎遇到了一些麻烦。


我只会发布我的主文件,希望它就足够了。


当我使用头文件和cpp编译时,你可以看到我有一个对象工厂数组,我得到'左边'。''植物名称''必须有类/结构/联合类型我所有变量的错误。我想我的构造函数可能有问题..


提前谢谢。


Hello!

I am a little stuck, I need to create a array of objects (class) and seem to having some troubles.

I will only post up my main file hopefully it will be enough.

You can see I have an array of object plant, when I compile with the header file and cpp, I get "left of ''.plantName'' must have class/struct/union type" errors on all my variables. I think I have a problem with my constructor maybe..

thankyou in advance.


展开 | 选择 | Wrap | 行号

推荐答案


您好!


我有点卡住了,我需要创建一个对象数组(类)并且似乎遇到了一些麻烦。


我只会发布我的主文件,希望它就足够了。


你可以看到我有一个对象工厂数组,当我用头文件和cpp编译时,我得到& ; .plantName''的左边必须有class / struct / union type"我所有变量的错误。我想我的构造函数可能有问题..


提前谢谢。


#include< ; iostream>

#include< string>

#include" nursery.h"


using namespace std;


int main()

{

int selection = 0;

int i = 0;


苗圃植物[10];

plant [i] .menu();

cin>>选择;


而(选择!= 4)

{

开关(选择)

{

案例1:plant [i] .addPlant();

休息;

案例2:plant [i] .waterPlant() ;

休息;

案例3:plant [i] .movePlant();

休息;

案例4://退出

休息;


默认:cout< ;< 非法菜单选择 <<结束;

}


};


系统(暂停);

}



首先,请在发布源代码时使用代码标签,方法是使用CODE标签包含源代码。

现在,您的源代码中存在一些明显的错误:

First of all, please use the code tags when posting source code by using by using the CODE tags to enclose source code.
Now, there are some obvious errors in your source code:

展开 | 选择 | Wrap | 行号


谢谢你的回复,我真的很感激它!


开关我当时基本上都是在我的头顶上写下来的,我已经对了ct它。


我可以附上其他文件,不过我不确定如何在这个论坛上这样做。


由于论坛指南我不想只是发布所有代码(复制和粘贴)


我该怎么办,只需发布​​所有必需的代码?


在此先感谢。


编辑:我已经解决了如何附加!!
thankyou for the reply, I really appreciate it!

the switch I was basically writing off the top of my head at the time, and I have since corrected it.

I could attach the other files, however I am unsure of how to do this on this forum.

Due to the forum guidelines I don''t want to just post up all the code(copy and paste)

What should I do, just post up all the required code?

Thanks in advance.

I have worked out how to attach!!



谢谢你的回复,我真的很感激!


那个开关当时基本上都是我的头脑,我已经纠正了它。


我可以附上其他文件,但我不确定如何在这个论坛上这样做。


由于论坛准则我不想只是发布所有代码(复制和粘贴)


我该怎么做,只需发布​​所有必需的代码?


先谢谢。


编辑:我已经找到了如何处理测速!
thankyou for the reply, I really appreciate it!

the switch I was basically writing off the top of my head at the time, and I have since corrected it.

I could attach the other files, however I am unsure of how to do this on this forum.

Due to the forum guidelines I don''t want to just post up all the code(copy and paste)

What should I do, just post up all the required code?

Thanks in advance.

I have worked out how to attach!!



我尝试了你的代码,并且有很多工厂没有定义错误。一旦我修复了它的工作。没有留下''.plant''必须是类错误。

I tried your code and there were a lot of ''plant'' not defined errors. Once I fixed those it worked. There was no left of ''.plant'' must be class error.


这篇关于C ++需要有关对象数组的帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆