我在下面的标题中遇到了构造函数签名的问题.编译器给我的消息:
Run Code Online (Sandbox Code Playgroud)error: expected ')' before '&' token
但我不知道为什么会发生这种错误,我不认为原因是编译器指示的.
#ifndef TextQuery
#define TextQuery
#include <fstream>
#include <map>
#include <memory>
#include <set>
#include <string>
#include <sstream>
#include <vector>
using std::ifstream;
using std::map;
using std::shared_ptr;
using std::set;
using std::string;
using std::istringstream;
using std::vector;
class TextQuery
{
public:
using line_no = vector<string>::size_type;
TextQuery(ifstream &); //!!!!error: expected ')' before '&' token
private:
shared_ptr<vector<string>> file; //input file
//map of each word to the set of the lines in which that word appears
map<string, shared_ptr<set<line_no>>> wm;
}; …Run Code Online (Sandbox Code Playgroud) 以下代码记录了一个错误:
致命错误:所有goroutine都在睡着-死锁!
package main
import "fmt"
func main() {
ch := make(chan int)
ch <- 1
fmt.Println(<-ch)
}
Run Code Online (Sandbox Code Playgroud)
但是,当我将代码更改为:
package main
import "fmt"
func assign (ch chan int) {
ch <- 1
}
func main() {
ch := make(chan int)
go assign (ch)
fmt.Println(<-ch)
}
Run Code Online (Sandbox Code Playgroud)
打印出“ 1”。
然后我使用了缓冲通道:
package main
import "fmt"
func main() {
ch := make(chan int, 2)
ch <- 1
ch <- 2
fmt.Println(<-ch)
fmt.Println(<-ch)
}
Run Code Online (Sandbox Code Playgroud)
也可以打印“ 1”和“ 2”。
我对此情况有些困惑。提前致谢!