鉴于代码:
#include <iostream>
#include <cctype>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
string s("ABCDEFGHIJKL");
transform(s.begin(),s.end(),s.begin(),tolower);
cout<<s<<endl;
}
Run Code Online (Sandbox Code Playgroud)
我收到错误:
呼叫没有匹配功能
transform(__gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, __gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, __gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, <unresolved overloaded function type>)
什么是"未解决重载函数类型"是什么意思?
如果我用tolower
我写的函数替换它,它不再是错误.
为什么先++x || ++y && ++z
计算++x
,即使运算符的优先级&&
高于||
?
我正在阅读The Little Schemer并对以下代码感到困惑:
((lambda (len)
(lambda (l)
(cond
((null? l) 0)
(else
(+ 1 (len (cdr l)))))))
eternity)
(define eternity
(lambda (x)
(eternity x)))
Run Code Online (Sandbox Code Playgroud)
代码是确定空列表,否则它永远不会停止.
为什么" len
"没有递归?
我写了一堂课
struct opera{
int a,b;
int op;
opera(int a1=0,int b1=0,int op1=-1):a(a1),b(b1),op(op1){}
opera& operator=(opera& tmp){
a=tmp.a;
b=tmp.b;
op=tmp.op;
}
Run Code Online (Sandbox Code Playgroud)
我想将它分配给这样的数组元素:
ans[a][b]= opera(t.a,t.b,i);
Run Code Online (Sandbox Code Playgroud)
为什么它无法成功编译.
但是这可以工作:
opera tmp=opera(t.a,t.b,i);
ans[a][b]= tmp;
Run Code Online (Sandbox Code Playgroud)
当然,struct opera不需要显式赋值函数,而且
ans[a][b]= opera(t.a,t.b,i);
Run Code Online (Sandbox Code Playgroud)
可以直接工作.
最近我用c ++练习算法.在这里练习:poj
我发现两个非常混乱的问题.我写了一个MAZE类,在MAZE中有三个主要功能,它们是
int left_path();int right_path();int mini_path();
打印答案的函数:
void display(){
cout<<left_path()<<" "<<right_path()<<" ";
cout<<mini_path()<<endl;
}
Run Code Online (Sandbox Code Playgroud)
程序可以正常工作.我们看到函数display()可以很容易; 我这样写
void display(){
cout<<left_path()<<" "<<right_path()<<" "<<mini_path()<<endl;
}
Run Code Online (Sandbox Code Playgroud)
只有一个变化;但是程序无法工作,它就像无限循环一样.
以下是另一个问题:函数mini_path的框架是这样的
int maze::mini_path(){
ini();
queue<pair<int,int> > q;
q.push(make_pair(x,y));
while(!q.empty()){
pair<int,int> tmp=q.front();
q.pop();
int t=...;
if(E){
return t;
}
if(E){
S
}
if(E){
S
}
if(E){
S
}
if(E){
S
}
}
return -1;
}
Run Code Online (Sandbox Code Playgroud)
如果最后有"return -1",则该函数正常工作,否则函数返回随机大数.
该程序只在一个文件中,我使用枪编译器.
我没有显示总代码,因为我认为没有人想看到它们.我只是想问一下哪些问题可能导致奇怪的行为.
源代码(问题2简化):
typedef enum {LEFT=-1,RIGHT=1,UP,DOWN} direction;
ifstream fin("file_test3.txt");
class maze{
public:
maze(){input();}
int mini_path();
void input();
void display(){ …
Run Code Online (Sandbox Code Playgroud)