VC++中过了,可在Borland里就不会过

liql2007 2008-07-17 01:51:23
求救!编译错误!
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
class RGB
{
public:
int r,g,b;
RGB(int x,int y,int z):r(x),g(y),b(z){}
};

double distance(RGB r1,RGB r2)
{
double x=pow((r1.r-r2.r),2.0);
double y=pow((r1.g-r2.g),2.0);
double z=pow((r1.b-r2.b),2.0);
return sqrt(x+y+z);
}
int main()
{
vector<RGB> front,back;
for(int i=0;i<16;i++)
{
int a,b,c;
cin>>a>>b>>c;
front.push_back(RGB(a,b,c));
}
for(int e,f,g;cin>>e>>f>>g;)
{
if(e==-1)
break;
back.push_back(RGB(e,f,g));
}
for(int j=0;j<back.size();j++)
{
double temp=distance(back[j],front[0]);
int sign=0;
for(int k=0;k<front.size();k++)
if(temp>distance(back[j],front[k]))
{
temp=distance(back[j],front[k]);
sign=k;
}
cout<<"("<<back[j].r<<","<<back[j].g<<","<<back[j].b
<<") maps to ("<<front[sign].r<<","<<front[sign].g
<<","<<front[sign].b<<")\n";
}
return 0;
}
...全文
150 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
勉励前行 2008-07-24
  • 打赏
  • 举报
回复

double distance(RGB r1,RGB r2) ;
1、這個函數 distance 與 std::distance 重名 , 最好改名
2、double distance(RGB r1,RGB r2) ;
參數使用傳值,最好改為傳地址 double distance(RGB const &r1,RGB const &r2) ;
值傳遞會調用 構造函數

3、你的 RGB 類中,只定義了一個構造函數 RGB(int,int,int); 這樣會導致沒有 RGB() 這樣的構造函數,建議加上構造函數 RGB().
不加上,可能通不過編譯的(要看STL中的模板怎麼實現了)。

現用 B2007 ,沒法幫你用B6調試。
cppowner 2008-07-18
  • 打赏
  • 举报
回复
distance是什么函数? 找到 点 和点 的距离 你的程序里面有代码。
一个模板类
liql2007 2008-07-17
  • 打赏
  • 举报
回复
你很强啊!distance是什么函数?为什么会冲突?
jxw1987628 2008-07-17
  • 打赏
  • 举报
回复


//---------------------------------------------------------------------------

#pragma hdrstop

//---------------------------------------------------------------------------

#pragma argsused
#include <iostream>
#include <vector>
#include <math.h>

class CRGB
{
public:
int r,g,b;
CRGB(int x,int y,int z):r(x),g(y),b(z){}
};

double _distance(CRGB r1,CRGB r2)
{
double x=pow((r1.r-r2.r),2.0);
double y=pow((r1.g-r2.g),2.0);
double z=pow((r1.b-r2.b),2.0);
return sqrt(x+y+z);
}
int main()
{
using namespace std;
vector <CRGB> front,back;
for(int i=0;i <16;i++)
{
int a,b,c;
cin>>a>>b>>c;
front.push_back(CRGB(a,b,c));
}
for(int e,f,g;cin>>e>>f>>g;)
{
if(e==-1)
break;
back.push_back(CRGB(e,f,g));
}
for(int j=0;j <back.size();j++)
{
double temp=_distance(back[j],front[0]);
int sign=0;
for(int k=0;k <front.size();k++)
if(temp>_distance(back[j],front[k]))
{
temp=_distance(back[j],front[k]);
sign=k;
}
cout <<"(" <<back[j].r <<"," <<back[j].g <<"," <<back[j].b
<<") maps to (" <<front[sign].r <<"," <<front[sign].g
<<"," <<front[sign].b <<")\n";
}
return 0;
}


帮你改正了,主要是distance这个函数冲突
  • 打赏
  • 举报
回复
bc5.5编译出错,应该是STL库的实现问题。
liql2007 2008-07-17
  • 打赏
  • 举报
回复
用的是C++Builder6.0。就是通不过
僵哥 2008-07-17
  • 打赏
  • 举报
回复
不知道你的编译器是什么版本,我使用的是C++Builder2007,没有问题。
liql2007 2008-07-17
  • 打赏
  • 举报
回复
本来就没先啊。
在ACM中在线提交就提示编译错误。
僵哥 2008-07-17
  • 打赏
  • 举报
回复
建议一个Console Application,有一个对话框,其中的VCL不要选
liql2007 2008-07-17
  • 打赏
  • 举报
回复
[C++ Error] _iterator_base.h(96): E2404 Dependent type qualifier 'RGB' has no member type named 'difference_type'
[C++ Error] _iterator_base.h(94): E2404 Dependent type qualifier 'RGB' has no member type named 'iterator_category'
[C++ Error] _iterator_base.h(95): E2404 Dependent type qualifier 'RGB' has no member type named 'value_type'
.......
liql2007 2008-07-17
  • 打赏
  • 举报
回复
[C++ Error] _iterator_base.h(94): E2404 Dependent type qualifier 'RGB' has no member type named 'iterator_category'
[C++ Error] _iterator_base.h(95): E2404 Dependent type qualifier 'RGB' has no member type named 'value_type'
[C++ Error] _iterator_base.h(96): E2404 Dependent type qualifier 'RGB' has no member type named 'difference_type'
还有。。。。
僵哥 2008-07-17
  • 打赏
  • 举报
回复
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
class RGB
{
public:
int r,g,b;
RGB(int x,int y,int z):r(x),g(y),b(z){}
};

double distance(RGB r1,RGB r2)
{
double x=pow((r1.r-r2.r),2.0);
double y=pow((r1.g-r2.g),2.0);
double z=pow((r1.b-r2.b),2.0);
return sqrt(x+y+z);
}
int main()
{
vector <RGB> front,back;
for(int i=0;i <16;i++)
{
int a,b,c;
cin>>a>>b>>c;
front.push_back(RGB(a,b,c));
}
for(int e,f,g;cin>>e>>f>>g;)
{
if(e==-1)
break;
back.push_back(RGB(e,f,g));
}
for(int j=0;j <back.size();j++)
{
double temp=distance(back[j],front[0]);
int sign=0;
for(int k=0;k <front.size();k++)
if(temp>distance(back[j],front[k]))
{
temp=distance(back[j],front[k]);
sign=k;
}
cout <<"(" <<back[j].r <<"," <<back[j].g <<"," <<back[j].b
<<") maps to (" <<front[sign].r <<"," <<front[sign].g
<<"," <<front[sign].b <<")\n";
}
return 0;
}
僵哥 2008-07-17
  • 打赏
  • 举报
回复
报什么错?

13,825

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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