void passfailactivity::func()
{
cout << "This is func function of passfailactivity" <<endl;
}
#include "passfailactivity.h"
using namespace std;
int main()
{
passfailactivity e;
e.msg();
e.func();
return 0;
}
I get these error on trying to run this on g++ under linux:
g++ prog.cpp -o prog
In file included from prog.cpp:1:
passfailactivity.h:2: syntax error before `{' token
passfailactivity.h:5: virtual outside class declaration
passfailactivity.h:6: syntax error before `public'
prog.cpp: In function `int main()':
prog.cpp:7: aggregate `passfailactivity e' has incomplete type and cannot be
defined
it's saying there is syntax errors in "passfailactivity.h" is this the file you just posted?
if not can you post it and please include code tags this time. the button that looks like <> over on the right.
// This is gradedActivity.h
class gradedactivity
{
protected:
char letter;
virtualvoid func();
public:
char getLetter()
{
return letter;
}
};
1 2 3 4 5 6 7 8
// This is GradedActivity.cpp
#include "gradedactivity.h"
void gradedactivity::func()
{
cout << "This is func function of gradedactivity" <<endl;
}
1 2 3 4 5 6 7 8 9 10
//This is passfailactivity.h
#include "gradedactivity.h"
class passfailactivity:public gradedactivity {
protected:
float passingscore;
virtualvoid func();
public:
void msg();
};
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
//This is passfailactivity.cpp
#include "passfailactivity.h"
void passfailactivity::msg()
{
cout << "In msg of passfailactivity" <<endl;
}
void passfailactivity::func()
{
cout << "This is func function of passfailactivity" <<endl;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
// This is main program prog.cpp
#include "passfailactivity.h"
usingnamespace std;
int main()
{
passfailactivity e;
e.msg();
//e.func();
return 0;
}
Now I am getting
g++ prog.cpp -o prog
/tmp/cc2HOyTl.o(.text+0x27): In function `main':
: undefined reference to `passfailactivity::msg()'
/tmp/cc2HOyTl.o(.gnu.linkonce.t._ZN16passfailactivityC1Ev+0x19): In function `passfailactivity::passfailactivity()':
: undefined reference to `vtable for passfailactivity'
/tmp/cc2HOyTl.o(.gnu.linkonce.t._ZN14gradedactivityC2Ev+0x8): In function `gradedactivity::gradedactivity()':
: undefined reference to `vtable for gradedactivity'
collect2: ld returned 1 exit status