- 论坛徽章:
- 0
|
/*-----------hello.h--------------*/
#include <stdio.h>;
class Testmath
{
public:
float pingjun(int aa,int bb,int cc);
int a;
int b;
int c;
};
/*-----------hello.cc--------------*/
#include "hello.h"
float Testmath::pingjun(int aa,int bb,int cc)
{
a=aa;
b=bb;
c=cc;
float avg;
avg=(float)(a+b+c)/3;
return avg;
}
/*-----------main.cc--------------*/
#include "hello.h"
main()
{
float num;
Testmath testmath;
num=testmath.pingjun(23,34,56);
printf("%f\n",num);
}
假如运行#gcc -o main main.cc
出现以下:/tmp/ccGe3L6y.o(.text+0x1b): In function `main':
: undefined reference to `Testmath::pingjun(int, int, int)'
/tmp/ccGe3L6y.o(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
假如运行#gcc -c hello.cc
#gcc -c main.cc
#gcc -o main hello.o main.o
回出现以下:
main.o(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
请各位帮忙,多谢! |
|