inheritance and using constructors

hey guys i wrote this code


this is the header file
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
30
31
32
33
34
35
36
37
#ifndef VAR_H
#define VAR_H

#include <iostream>
#include <cstring>
using namespace std;
class variable;
typedef enum
{

	uu,
	tt,
	ff,
}trivalue;

class formula
{

public:

	trivalue Formula;

	formula (trivalue & form);
	void setvalue (trivalue v);

};

class variable
{ public :

	char name[8];
	variable (char * name);
	variable ();
friend class formula;
};

#endif  



this s the c plus plus file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include "var.h"
using namespace std;

formula::formula(trivalue &form)
{

	form=uu;
};

void formula::setvalue (trivalue v)
{

	Formula=v;

};

variable::variable ()
{
	
	strncpy_s (name," ",8);
}


i need to use the base constructor of formula in the constructor variable in order to set the value to unknown. i really dont know how to write that in c++
any help please? one more thing, did i use iheritance the way it is supposed to be used? in other words did i write the code right?
thank you guys
This is not inheritance but rather, friendship.

Aceix.
If Variable is to inherit from Formula you have to define it as a child class, which you have not done.

Then during the implementation of the constructor for Variable you can define which constructor to using from Formula using : formula(value)

e.g
1
2
3
4
5
6
7
8
9
10
class Base {
public:
 explicit Base(int x) { };
 explicit Base(string x) { };
}

class Child : public Base {
 Child(int x, unsigned y) : Base(x) { } // Calls the int base constructor
 Child() : Base("hello") { } // Calls the string base constructor
}
thank you guys :)
Topic archived. No new replies allowed.