Member function

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include "ShippingContainer.h"
#include "ManualShippingContainer.h"
#include "RFIDShippingContainer.h"

int main(){

	ShippingContainer *theShippingContainer[6] ;
	theShippingContainer[0] =	new ManualShippingContainer;
	theShippingContainer[1] =	new ManualShippingContainer;
	theShippingContainer[2] =	new ManualShippingContainer;
	theShippingContainer[3] =	new RFIDShippingContainer;
	theShippingContainer[4] =	new RFIDShippingContainer;
	theShippingContainer[5] =	new RFIDShippingContainer;
	
	for(int i = 0; i < 3; i ++){
		
        theShippingContainer[i]->setContainerID();
		//theShippingContainer[i]->getContainerID();
        theShippingContainer[i]->getContent();//this one
	}


	system( "pause" );//System Pause
	return 0;
}


code is havent finish , just meet a small problem.
my getContent() is inside the ManualShippingContainer class , but i thought i already set the pointer to point to class for ManualShippingContainer d ? why it's cant access the data to it
please show your "ManualShippingContainer" code...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include "ShippingContainer.h"

class ManualShippingContainer : public ShippingContainer{
	// derived class for manual method of inventorying the container
private:
	string Content;
public:
	ManualShippingContainer (string Content); // string content represents, for example, "4 crates of apples
	ManualShippingContainer ();// constructors
        
	string getContent();// input string of the content.
        
	string getManifest();//output the empty string as the content of the shipping container.
};

ManualShippingContainer ::ManualShippingContainer (string Content){}

ManualShippingContainer ::ManualShippingContainer() : Content(""){}

string ManualShippingContainer :: getContent(){
	cout<< "Please enter the content of the item.\n";
	cin>> Content;
	return Content;
}

string ManualShippingContainer :: getManifest(){
	cout<< getContainerID() << ":" << Content <<endl;
	return Content;
}
the error state the ShippingContainer don't have the member of getContent() , but i thought the pointer already point to the ManualShippingContainer ? @@
because you have to access it through "ManualShippingContainer". this is because "ShippingContainer" don't have "getContent" function, instead "ManualShippingContainer" does have... you should declare the "getContent()" using virtual

CMIIW
Topic archived. No new replies allowed.