0

Not necessarily hard I just have a hard time where to exactly inherit the , I have a bass class and 2 separate classes which inherit the base class

Lets class base class - Class A

Other two classes - Class B and Class C

Class A has the following pseudo code schema

public:
        int returnDay() const;
        float returnAmount() const;
        string returnCust() const;
       Constructor(parametized default values);
       void Initialize(int, float, string);
private:
   int day;
  float amount;
  string customer;

Class B is very similiar

public:
        int returnQuantity() const;
        string returnItemNum() const;
       Constructor(parametized default values);
       void Initialize(int, float, string, string, int);
private:
   string itemNumber;
  int quantity

Class C is very much like B
If i know how to implement class B while inheriting from the base Class A then I can do it to the other class

I dont exactly know what to inherit my guess is the Initialize function in the base class when your implementing the Initialize function in Class B ? but who knows its not working quite right

3
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by firstPerson
0

To my knowledge you can't specify what to inherit and what not. You either inherit the whole shebang or you don't inherit anything. I always am receptive to being shown wrong, and thereby learn in the process, however.

0

Well my best guess is that the function used from the base class into either separate classes is the Initialize function

However If say in the implementation of class B or C

In my implementation file I have

void Class B::Initialize(int, float, string, int, string) : Initialize(...

It would not work because I believe it has to be called as a constructor
and when I call it in the function it doesnt work either Im sort of lost

0

To my knowledge you can't specify what to inherit and what not. You either inherit the whole shebang or you don't inherit anything. I always am receptive to being shown wrong, and thereby learn in the process, however.

You know I wasn't 100% sure. Then I tried it. Tell me what you think :

#include<iostream>
#include<sstream>

using namespace std;

class A
{
private :
	int aVar;

public:
	
	static void attack() { cout <<"Rarr\n"; }	

	int run() { return 0; }

	struct A_o 
	{
		int x;
		A_o() { x = 0; }	
		void Roar(){ A::attack(); }
	};
};

class B : public A::A_o
{
public:
	void Roar(){
		this->A_o::Roar(); 
	}
	
	//Error below
	//void flee() { A::run(); };
};

int main()
{ 	
	B classB;

	classB.Roar();

	return 0;

}

Its inheriting A_o( part of A) and not the whole class A, if that
is what you mean.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.