我如何完成此代码 [英] How do I complete this code

查看:74
本文介绍了我如何完成此代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hive.cpp

hive.cpp

#include "Hive.h"
#include <iostream>

using namespace std;

namespace HiveSpace
{
	Hive::Hive()
	{
		what to write here? //Create an instance of each derived class
	}
	
	void Hive::activity()
	{
		???? //Polymorphically call each classes work function
	}
	
	Hive::~Hive()
	{
		????? //Deal with dynamic memory
	}
}



hive.h


hive.h

#ifndef HIVE_H
#define HIVE_H

#include "Bee.h"
#include "Queen.h"
#include "Drone.h"
#include "Worker.h"

namespace HiveSpace
{
	class Hive
	{
		private:
			Bee* queen;
			Bee* worker;
			Bee* drone;
		
		public:
			Hive();
			void activity();
			~Hive();
	};
}

#endif

推荐答案

你的ctor需要创建成员,dtor需要删除它们而activity()需要调用它们共享的虚拟内容



你应该阅读课程记录,或与您的导师/讲师交谈
your ctor needs to create the members, the dtor needs to delete them and activity() needs to call whatever virtual they all share

you should maybe read the course notes again, or talk to your tutor/lecturer


这篇关于我如何完成此代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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