abstract class

I am trying to declare in main() an object of class var1, yet an error occurs stating
''[Error] cannot declare variable 'q' to be of abstract type 'var1' ''

also I want to ask if the derived class can be used as my own namespace...

namespace derived_class_var1
{
class var1: public var
{
...
}
}

any recommendation will be highly appreciated!

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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
  #include<iostream>
  #include <cstring>
  
  using namespace std;
  
  class var
  {
  		
    int A;
    
    double B;
    
    char C;
    
    char c [256];
    
    string S;
    
    
     public:
     	
     var(int A=NULL){this->A=A; this->B=NULL; this->C=0; this->c[0]=0; this->S.clear(); }
	 
	 var(double B){this->A=NULL; this->B=B; this->C=C; this->c[0]=0; this->S.clear(); }
	 
	 var(char C){this->A=NULL; this->B=NULL; this->C=0; this->c[0]=0; this->S.clear(); }
	 
	 var(char c[]){this->A=NULL; this->B=NULL; this->C=0; strcpy(this->c,c); this->S.clear(); }
	 
	 var(string S){this->A=NULL; this->B=NULL; this->C=0; this->c[0]=0; this->S=S; }
	 
	 var(int A, double B, char C, char c[], string S){this->A=A; this->B=B; this->C=C; strcpy(this->c,c); this->S=S; }
	 
	 var(var&Obj){this->A=Obj.A; this->B=Obj.B; this->C=Obj.C; strcpy(this->c,Obj.c); this->S=Obj.S; }
	 	
     	
      virtual void setA() =0;
      
      virtual void setB() =0;
      
      virtual void setC() =0;
      
      virtual void setc() =0;
      
      virtual void setS() =0;
       
      virtual void setAManual() =0;
      
      virtual void setBManual() =0;
      
      virtual void setCManual() =0;
      
      virtual void setcManual() =0;
      
      virtual void setSManual() =0;
       
      virtual const int getA () const =0;
      
      virtual const double getB () const =0;
      
      virtual const char getC () const =0;
      
      virtual const char* getc () const =0;
      
      virtual const string getS () const =0;
      
      virtual  double SUM(int A, double B) =0;
      
  };
  

  
  class var1: public var
  {
  		
  	int a;
    
    double b;
    
    char CH;
    
    char str [256];
    
    string s;
  		
  	public:
  		
  	 var1(int a=NULL){this->a=a; this->b=NULL; this->CH=0; this->str[0]=0; this->s.clear(); }
	 
	 var1(double b){this->a=NULL; this->b=b; this->CH=CH; this->str[0]=0; this->s.clear(); }
	 
	 var1(char CH){this->a=NULL; this->b=NULL; this->CH=0; this->str[0]=0; this->s.clear(); }
	 
	 var1(char str[]){this->a=NULL; this->b=NULL; this->CH=0; strcpy(this->str,str); this->s.clear(); }
	 
	 var1(string s){this->a=NULL; this->b=NULL; this->CH=0; this->str[0]=0; this->s=s; }
	 
	 var1(int a, double b, char CH, char str[], string s){this->a=a; this->b=b; this->CH=CH; strcpy(this->str,str); this->s=s; }
	 
	 var1(var1&Obj){ this->a=Obj.a; this->b=Obj.b; this->CH=Obj.CH; strcpy(this->str,Obj.str); this->s=Obj.s; }
	 
	 ~var1(){}
	 
	   void setA(int a) {this->a=a;}
      
       void setB(double b) {this->b=b;}
      
       void setCH(char CH) {this->CH=CH;}
      
       void setSTR(char str[]) {strcpy(this->str,str);}
      
       void setS(string s) {this->s=s;}
       
       void setAManual() {cout<<"Enter a= "; cin>>this->a;}
      
       void setBManual() {cout<<"Enter b= "; cin>>this->b;}
      
       void setCHManual() {cout<<"Enter CH= "; cin>>this->CH;}
      
       void setSTRManual() {cout<<"Enter STR= "; cin>>this->str;}
       
       void setSManual() {cout<<"Enter s= "; cin>>this->s;}
       
       const int getA () const {return this->a;}
      
       const double getB () const {return this->a;}
      
       const char getCH () const {return this->CH;}
      
       const char* getSTR () const {return this->str;}
      
       const string getS () const {return this->s;}
      
        SUM(int a, double b) {cout<<"SUM="; return a+b;}
      
  };
 
  

  
  int main()
  {

  	
  	var1 q(6);
  	
  	return 0;
  }
A function that is supposed to override a base function needs the same signature, i.e. the same parameter and return type. In your case setA(...) is already different.

Consider using the keyword override like so:

void setB(double b) override {this->b=b;}

Then the compiler will tell you what function does not match.
@coder777, thanks, will try
Topic archived. No new replies allowed.