I got below compile errors, need some inputs to fix it and improve the 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 30 31 32 33 34 35
|
#include <iostream>
using namespace std;
class Foo
{
public:
virtual void func() const = 0;
};
class Bar: public Foo
{
public:
Bar(): data (new int[10]) ()
~Bar() {}
void func() const{
data++;
}
int get()
{
return data;
}
private:
int *data;
};
Foo *foo = makeBar();
foo->func():
return 0;
}
int main()
{
cout<<"Code runs good";
return 0;
}
|
Output errors:
main.cpp: In constructor ‘Bar::Bar()’:
main.cpp:20:27: error: expected ‘{’ before ‘(’ token
Bar(): data (new int[10]) ()
^
main.cpp: In member function ‘virtual void Bar::func() const’:
main.cpp:23:5: error: increment of member ‘Bar::data’ in read-only object
data++;
^~
main.cpp: In member function ‘int Bar::get()’:
main.cpp:27:8: error: invalid conversion from ‘int*’ to ‘int’ [-fpermissive]
return data;
^~~~
main.cpp: At global scope:
main.cpp:32:20: error: ‘makeBar’ was not declared in this scope
Foo *foo = makeBar();
^
main.cpp:33:1: error: ‘foo’ does not name a type
foo->func():
^~~
main.cpp:35:1: error: expected declaration before ‘}’ token
}