小编Piu*_*sch的帖子

C++ | cout,打印返回的对象

我遇到了一个问题,我无法通过cout打印返回的对象.

我觉得很难描述所以我写了一个非常基本的程序来显示我的问题.

编译器在运算符<<中表示类型不匹配.

重载+返回一个Integer对象,但为什么不能打印?

"Test.cpp的"

#include <iostream>
#include "Integer.h"
using namespace std;
int main() {
Integer int1(5);
Integer int2(2);
cout << (int1 + int2) << endl;  // Here it fails
cout << int2 << endl;           // Works
return 0;
}
Run Code Online (Sandbox Code Playgroud)

"Integer.cpp"

#include "Integer.h"
Integer::Integer(int integer) {
 this->integer = integer;
}
int Integer::get_integer() 
return integer;
}
Integer Integer::operator +(Integer& integer) {
return Integer(this->integer + integer.get_integer());
}
ostream& operator<<(ostream& output, Integer& integer) {
output << integer.get_integer();
return output;
}
Run Code Online (Sandbox Code Playgroud)

"Integer.h"

#include <iostream> …
Run Code Online (Sandbox Code Playgroud)

c++ cout operator-overloading

5
推荐指数
1
解决办法
411
查看次数

Scala检查List是否包含其他List的元素片

A : List[String] 
B : List[String]
Run Code Online (Sandbox Code Playgroud)

我想知道List B的任何元素是否是列表A的任何元素的片段.

什么是最快的检查方式?

scala list

3
推荐指数
2
解决办法
7404
查看次数

达到队列大小时该怎么办?

我正在将Slick 3.0和HikariCP 2.3.8一起使用(也可以玩2.4)

我做了很多数据库IO,并且不断达到队列限制。有没有一种方法可以获取当前的队列大小,如何增加队列大小?还是建议这样做,还是将带有自己队列的数据库包装器作为更好的选择?

我指的是例外:

java.util.concurrent.RejectedExecutionException: Task slick.backend.DatabaseComponent$DatabaseDef$$anon$2@39496345 rejected from java.util.concurrent.ThreadPoolExecutor@21ee20b4[Running, pool size = 20, active threads = 20, queued tasks = 1000, completed tasks = 7021]
Run Code Online (Sandbox Code Playgroud)

scala slick hikaricp

3
推荐指数
2
解决办法
2114
查看次数

包含标题的枚举| 错误未声明

Maumau_game.h:

#ifndef MAUMAU_GAME_H_
#define MAUMAU_GAME_H_

#include <more_includes>
#include "Player.h"

enum game_status {
    STATUS_NONE = 0,
    STATUS_DRAW_2 = 1,
};

class Maumaugame_holder {
methods();
};

#endif /* MAUMAU_GAME_H_ */
Run Code Online (Sandbox Code Playgroud)

Player.h:

#ifndef PLAYER_H_
#define PLAYER_H_

#include <vector>
#include "Maumau_game.h"
#include "Card.h"

class Player {
more_methods();

public:
    void do_turn(game_status g_status, const Card upper_dropped_card,
            Deck& talon); //Error: >>game_status<< not declared 


};

#endif /* PLAYER_H_ */
Run Code Online (Sandbox Code Playgroud)

我不知道为什么没有声明枚举game_status.我已正确包含标题,它在范围内,不是吗?我无法在"Player.h"中声明枚举.我会宣布它两次.你能帮我吗?你有什么建议吗?

(我不允许使用C++ 11)

提前致谢

c++ enums declaration

1
推荐指数
2
解决办法
5075
查看次数

标签 统计

c++ ×2

scala ×2

cout ×1

declaration ×1

enums ×1

hikaricp ×1

list ×1

operator-overloading ×1

slick ×1