undefined reference to 错误 恳请高手指点

dyf6372 2011-11-25 08:52:36
小弟写了一个简单排序的算法,linux下用codeblocks编译老报错:"undefined reference"。在windows 用vs2010正常编译运行。想请教一下,到底哪有问题???

main.cpp文件:
#include <iostream>
#include "simpleSort.h"

#define NUM 100

using namespace std;

int main(){
int num;
float a[NUM];
cout<<"请输入所有数的个数:";
cin>>num;
for(int i=0;i<num;i++){
cout<<"第"<<i+1<<"个:";
cin>>a[i];
}

SSort *sSort = new SSort(a,num);
sSort->sort();
sSort->display();
}

simpleSort.h文件:
#ifndef SIMPLESORT_H_INCLUDED
#define SIMPLESORT_H_INCLUDED
#include<iomanip>

using namespace std;

class SSort
{
float* a;
int num;
public:
SSort(float x[],int n);
void sort();
void display();
};
#endif // SIMPLESORT_H_INCLUDED


simpleSort.cpp文件:
#include <iostream>
#include<iomanip>
#include "simpleSort.h"

using namespace std;
SSort::SSort(float x[],int n){
a=x;
num=n;
}

void SSort::sort(){
int count;
float min,temp;
for(int j=0;j<num;j++){
min=1000.0f;
count=-1;
for (int i=j;i<num;i++){
if(a[i]<min){
min=a[i];
count=i;
}
}
temp=a[count];
a[count]=a[j];
a[j]=temp;
}
}

void ISort::display(){
cout<<"简单选择排序:"<<endl;
for(int i=0;i<num;i++) cout<<setprecision(3)<<a[i]<<" ";
cout<<endl;
}

错误信息:
undefined reference to `SSort::SSort(float*, int)'
undefined reference to `SSort::sort()'
undefined reference to `SSort::display()'
...全文
705 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
dyf6372 2011-11-25
  • 打赏
  • 举报
回复
谢谢四楼 放在同一个文件夹内,但真的是没加进去哦 万分感谢
柯本 2011-11-25
  • 打赏
  • 举报
回复
simpleSort.cpp没有加入你的工程
dyf6372 2011-11-25
  • 打赏
  • 举报
回复
这是codeblocks编译时出的完整错误
obj/Debug/main.o||In function `main':|
/searchAndSort/main.cpp|21|undefined reference to `SSort::SSort(float*, int)'|
/searchAndSort/main.cpp|22|undefined reference to `SSort::sort()'|
/searchAndSort/main.cpp|23|undefined reference to `SSort::display()'|
||=== Build finished: 3 errors, 0 warnings ===|
xunxun 2011-11-25
  • 打赏
  • 举报
回复
你的full command log呢?
恨天低 2011-11-25
  • 打赏
  • 举报
回复
属于链接错误,找不到类成员方法的实现。你的makefile怎么写的?

64,282

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧