I got the following error wwhile compiling this c++ code . What can be the reason behind this ?
# include <iostream>
# include <stdio.h>
# include <conio.h>
using namespace std;
class Foo
{
int a;
public :
virtual void Fun1();
Foo()
{a=5;}
};
Class X: public Foo // Error class does not name a type
{
Foo f;
public:
void Fun1() { }
X()
{
memset(&f,0x0,sizeof(f));
}
};
int main()
{
X x; // Error 'X undeclared and expected ; before x, i guess because of first one
getch();
return 0;
}
The keyword
classbegins with a lower-casec. That will fix the errors you reported, but more errors remain.You declare
Foo::Fun1, but don’t define it.Finally you’ll need to include
<cstring>for the declaration ofstd::memset. It’s possible that another header is including it indirectly, but you can’t rely on that.You’ll then have undefined runtime behaviour, since it’s not valid to use
memsetto overwrite non-POD objects –Foohas a virtual function, and so is not POD.