how do i publically inherit the subclass from the base class



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
  #include "stdafx.h"
#include <iostream>
#include <fstream>
using namespace std;
 
template <class game>
 
class game
{
private:
 
protected:
    int nintendo;
    int sega;
    string fun;
    bool enjoy;
public:
 
};
closed account (E0p9LyTq)
1
2
3
4
5
6
7
8
9
10
class Base
{
   // your base class methods and data members
};

class Derived : public Base
{
   // your derived class methods and data members
   // derived can use the base class methods and data members.
};
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 "stdafx.h"
#include <iostream>
#include <fstream>
using namespace std;

template <class game>

class game
{
private:

protected:
	int nintendo;
	int sega;
	string fun;
	bool enjoy;
public:
	
};

class game2 : public game
{
private:

protected:

public:

};


it gave me an error how can i fix
closed account (E0p9LyTq)
it gave me an error how can i fix

Delete line 6. (template <class game>)

When you get an error, copy and paste the error, please. Just saying "I have an error" is not very helpful.
Error	C2955	'game': use of class template requires template argument list	Project1	c:\programming\my projects\project1\project1\source.cpp	25	
Error (active)	E0441	argument list for class template "game" is missing	Project1	c:\Programming\My Projects\Project1\Project1\Source.cpp	24	
Last edited on
the teacher said i have use templates
closed account (E0p9LyTq)
If you are required to use class templates:
https://stackoverflow.com/questions/8810224/inheriting-from-a-template-class-in-c
https://stackoverflow.com/questions/10758686/template-class-inheritance

IMO class templates are not a beginner's subject.

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
#include "stdafx.h"
#include <iostream>
#include <fstream>
using namespace std;

template<class gamer>

template<class gamer> class game
{
private:

protected:
	int nintendo;
	int sega;
	string fun;
	bool enjoy;
public:
	
};

template<class gamer> class game2 : public game
{
private:

protected:

public:

};


Severity Code Description Project File Line Suppression State
Error C3857 'game': multiple template parameter lists are not allowed assignment2 abel c:\users\acmoo\source\repos\assignment2 abel\assignment2 abel\assignment2 abel.cpp 6

Severity Code Description Project File Line Suppression State
Error C2955 'game': use of class template requires template argument list assignment2 abel c:\users\acmoo\source\repos\assignment2 abel\assignment2 abel\assignment2 abel.cpp 22

sorry i dont know much
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 <iostream>
#include <fstream>

using namespace std;

template<class gamer> 
class game
{
private:

protected:
	int nintendo;
	int sega;
	string fun;
	bool enjoy;
public:
	
};

template<class gamer> 
class game2 : public game<gamer>
{
private:

protected:

public:

};

Last edited on
thanks peter87
Topic archived. No new replies allowed.