我想将一个数组传递给构造函数,但只传递第一个值 - 其余的看起来像垃圾.
这是我正在研究的简化版本:
#include <iostream>
class board
{
public:
int state[64];
board(int arr[])
{
*state = *arr;
}
void print();
};
void board::print()
{
for (int y=0; y<8; y++)
{
for (int x=0; x<8; x++)
std::cout << state[x + y*8] << " ";
std::cout << "\n";
}
}
int main()
{
int test[64] = {
0, 1, 2, 3, 4, 5, 6, 7,
1, 2, 3, 4, 5, 6, 7, 8,
2, 3, 4, 5, 6, 7, 8, 9, …
Run Code Online (Sandbox Code Playgroud) 我想比特移位一个变量并存储一个在布尔中移出的位.
就像是:
unsigned int i = 1;
bool b = rshift(&i); // i now equals 0 and b is set to true
Run Code Online (Sandbox Code Playgroud)
如何实现这一目标?
以下代码导致此错误:
if (bestLine.size() > searchDepth - depth)
bestLine.erase(bestLine.begin(), bestLine.end() - searchDepth - depth);
Run Code Online (Sandbox Code Playgroud)
当我检查searchDepth - depth
错误时的值时,它是0
.
基本上,
if (bestLine.size() > 0)
bestLine.erase(bestLine.begin(), bestLine.end());
Run Code Online (Sandbox Code Playgroud)
导致此错误.(或者不是.请参阅下面的评论.)
据我所知,上面的代码应该擦除整个向量,这是在这种情况下的期望行为.
我究竟做错了什么?
在我添加之前,所有内容都在编译 vector<Move> bestLine;
search.h
#ifndef SEARCH_H
#define SEARCH_H
#include <vector>
#include "types.h"
#include "position.h"
#include "move.h"
#include "moves.h"
U8 searchDepth;
U8 searchCount;
vector<Move> bestLine; // The compiler doesn't like this.
void searchPosition(Position &P, U8 depth);
void searchMove(Move &M);
#endif
Run Code Online (Sandbox Code Playgroud)
我收到的错误是:
1>d:\test\search.h(12): error C2143: syntax error : missing ';' before '<'
1>d:\test\search.h(12): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\test\search.cpp(30): error C2065: 'bestLine' : undeclared identifier
Run Code Online (Sandbox Code Playgroud)
似乎编译器没有识别Move
,所以bestLine
没有被声明.我认为这可能是一个循环依赖,并尝试声明一个不完整的类型Move
,但它没有任何影响.有人可以解释我错过的东西吗?