avatar
please help debug this code# Programming - 葵花宝典
m*k
1
An American company sets up a joint venture in China with a Chinese national
. The Euro company contributes IP and transfers $1,000,000.00 USD to the
China sub which then converts the dollars into RMB.
1. Do you know if there are any restrictions ( or what the process is)
to convert the RMB back to USD?
2. Are there any restrictions to taking the original $1,000,000.00 USD
out of China?
3. Are there any restrictions (Chinese government approvals) to
taking converting additiona
avatar
j*n
2
【 以下文字转载自 ChineseClassics 讨论区 】
发信人: tongxiao (tongxiao), 信区: ChineseClassics
标 题: 鹧鸪天(聊目之MM) 次丽狼韵
发信站: BBS 未名空间站 (Sun Feb 28 15:41:44 2010, 美东)
春暖元夕绿一时,柔风拂面缓离思。
新芽初泛蜗居院,莺上梢头第几枝。
意切切,雨丝丝。豆棚瓜架弄清词。
书中谁解颜如玉,翠袖盈盈诉相知。
打油瞎凑
avatar
j*7
3
在国外如何使用国内大学的IP登录CNKI,想用那个统计的数据库写论文,急!
写文章又耗到最后一天了,希望大家帮忙!多谢!
avatar
l*s
4
MSVC老是抱怨没有《右边是TEntry类型的重载,但是明明一开始就重载了啊,到底怎么
回事请大家看看。
(这段代码来自于Think in C++)
#include
#include
#include
#include
#include
#include
#include
using namespace std;
typedef map> Thesaurus;
typedef pair> TEntry;
typedef Thesaurus::iterator TIter;
ostream& operator<os << t.first <ostream_iterator out_it(os," ");
copy(t.second.begin(),t.second.end(),out_it);
return os;
}
class ThesaurusGen{
static const string letters;
static int count;
public:
int maxSize() { return letters.size(); }
ThesaurusGen(){ srand(time(0)); }
TEntry operator()(){
TEntry result;
if(count>=maxSize()) count=0;
result.first=letters[count++];
int entries=(rand() % 5)+2;
for(int i=0;iint choice=rand()% maxSize();
char cbuf[2]={0};
cbuf[0]=letters[choice];
result.second.push_back(cbuf);
}
return result;
}
};
int ThesaurusGen::count=0;
const string ThesaurusGen::letters("
ABCDEFGHIJKLMNOPQRSTUVWZYZabcdefghijklmnopqrsstuvwxyz");
int main(){
Thesaurus thesaurus;
generate_n( inserter(thesaurus, thesaurus.begin()),10,ThesaurusGen());
ostream_iterator out_it(cout,"\n");
copy(thesaurus.begin(),thesaurus.end(),out_it);
while(true){
cout<for(TIter it=thesaurus.begin(); it != thesaurus.end(); it++)
cout<cout<string reply;
cin >> reply;
if(reply.at(0) == '0' ) return 0;
if(thesaurus.find(reply) == thesaurus.end())
continue;
vector& v=thesaurus[reply];
copy( v.begin(),v.end(),ostream_iterator(cout," "));
cout<}
} // /:~

avatar
j*7
5
自己顶一下!
avatar
t*t
6
where is error message?
such a long program, you want reader to install a VC for this?

【在 l*********s 的大作中提到】
: MSVC老是抱怨没有《右边是TEntry类型的重载,但是明明一开始就重载了啊,到底怎么
: 回事请大家看看。
: (这段代码来自于Think in C++)
: #include
: #include
: #include
: #include
: #include
: #include
: #include

avatar
l*s
7
c:\program files\microsoft visual studio 9.0\vc\include\iterator(308) :
error C2679: binary '<operand of type 'const TEntry' (or there is no acceptable conversion)
c:\program files\microsoft visual studio 9.0\vc\include\iterator(307)
: while compiling class template member function 'std::ostream_iterator<_ty>> &std::ostream_iterator<_ty>::operator =(const _Ty &)'
1> with
1> [
1> _Ty=TEntry
1> ]
1> c:\documents and settings\gz\my documents\visual studio 2008\
projects\test3\test3\test3.cpp(58) : see reference to class template
instantiation 'std::ostream_iterator<_ty>' being compiled
1> with
1> [
1> _Ty=TEntry
1> ]
不好意思,这个VC的错误也很长的说

【在 t****t 的大作中提到】
: where is error message?
: such a long program, you want reader to install a VC for this?

avatar
t*t
8
interesting enough, it seems that ostream_iterator will not consider
overloaded operator<< in global namespace. i tried on gcc 4.4.4 and 4.6.0,
they both failed. however if I overload the operator<< in namespace std, it
can pass. And if you do not invoke the operator<< in ostream_iterator, it is
ok as well, no matter which namespace you use.
I am not sure whether this is a more strict constraint that existed long ago
but not enforced, or this is a bug. and interesting enough, both gcc and VC
has this bug??? probably not likely...

【在 l*********s 的大作中提到】
: MSVC老是抱怨没有《右边是TEntry类型的重载,但是明明一开始就重载了啊,到底怎么
: 回事请大家看看。
: (这段代码来自于Think in C++)
: #include
: #include
: #include
: #include
: #include
: #include
: #include

avatar
l*s
9
OoOo, 那估计就是Brue Eckel写书的时候标准里有些限制,编译器没有实现了。

it
is
ago
VC

【在 t****t 的大作中提到】
: interesting enough, it seems that ostream_iterator will not consider
: overloaded operator<< in global namespace. i tried on gcc 4.4.4 and 4.6.0,
: they both failed. however if I overload the operator<< in namespace std, it
: can pass. And if you do not invoke the operator<< in ostream_iterator, it is
: ok as well, no matter which namespace you use.
: I am not sure whether this is a more strict constraint that existed long ago
: but not enforced, or this is a bug. and interesting enough, both gcc and VC
: has this bug??? probably not likely...

avatar
t*t
10
OK, solved. let me explain this, this is complex.
you called copy(....begin(), ....end(), ostream_iterator<...>(...)), so
ostream_iterator will do the << for you. naturally, ostream_iterator is
within namespace std, so operator<< is called in namespace std.
Now for overload resolution. there are a lot of operator<< within namespace
std; so these are considered. your parameters to operator<< are std::basic_
ostream<...> and std::pair<...>, they are both in namespace std. Therefore
no other namespaces are considered. This means your definition in global
namespace is not considered.
Now if on the other hand, one of your parameters of operator<< is your own
class, let's say X, within global namespace, then global namespace will be
considered for function overload resolution. for example:
#include
#include
#include
struct X {
int x;
};
using namespace std;
ostream& operator<{
os<return os;
}
int main()
{
set a;
copy(a.begin(), a.end(), ostream_iterator(cout, " "));
}
This will be OK. However if you define X inside namespace A, like this:
#include
#include
#include
namespace A {
struct X {
int x;
};
}
using namespace std;
using namespace A;
ostream& operator<{
os<return os;
}
int main()
{
set a;
copy(a.begin(), a.end(), ostream_iterator(cout, " "));
}
This will not pass, unless you define the operator<< in either namespace std
, or namespace A.
Reference:
http://stackoverflow.com/questions/5195512/namespaces-and-opera

it
is
ago
VC

【在 t****t 的大作中提到】
: interesting enough, it seems that ostream_iterator will not consider
: overloaded operator<< in global namespace. i tried on gcc 4.4.4 and 4.6.0,
: they both failed. however if I overload the operator<< in namespace std, it
: can pass. And if you do not invoke the operator<< in ostream_iterator, it is
: ok as well, no matter which namespace you use.
: I am not sure whether this is a more strict constraint that existed long ago
: but not enforced, or this is a bug. and interesting enough, both gcc and VC
: has this bug??? probably not likely...

avatar
X*r
11
Nice explanation.
To put it simply, name lookup occurs before overload resolution.
As soon as the compiler find the name in the 'right' scope, it
will only try to get the function with the right signature from
this scope.
A minimal example:
void f(int) {}
namespace n {
void f() {}
void g() {
f(1); // will not compile, unless void f(){} is removed.
}
} // namespace n
(Of course, there is more than this, but thrust already explained
in detail)

namespace

【在 t****t 的大作中提到】
: OK, solved. let me explain this, this is complex.
: you called copy(....begin(), ....end(), ostream_iterator<...>(...)), so
: ostream_iterator will do the << for you. naturally, ostream_iterator is
: within namespace std, so operator<< is called in namespace std.
: Now for overload resolution. there are a lot of operator<< within namespace
: std; so these are considered. your parameters to operator<< are std::basic_
: ostream<...> and std::pair<...>, they are both in namespace std. Therefore
: no other namespaces are considered. This means your definition in global
: namespace is not considered.
: Now if on the other hand, one of your parameters of operator<< is your own

avatar
l*s
12
叹为观止,楼上两位太牛叉了!
avatar
z*e
13
那是师傅们,学着点!

【在 l*********s 的大作中提到】
: 叹为观止,楼上两位太牛叉了!
avatar
h*o
14
thrust you are so NB

it
is
ago
VC

【在 t****t 的大作中提到】
: interesting enough, it seems that ostream_iterator will not consider
: overloaded operator<< in global namespace. i tried on gcc 4.4.4 and 4.6.0,
: they both failed. however if I overload the operator<< in namespace std, it
: can pass. And if you do not invoke the operator<< in ostream_iterator, it is
: ok as well, no matter which namespace you use.
: I am not sure whether this is a more strict constraint that existed long ago
: but not enforced, or this is a bug. and interesting enough, both gcc and VC
: has this bug??? probably not likely...

avatar
l*s
15
nod nod

【在 z****e 的大作中提到】
: 那是师傅们,学着点!
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。