小编Vog*_*guo的帖子

错误:在'&'标记之前预期')'

我在下面的标题中遇到了构造函数签名的问题.编译器给我的消息:

error: expected ')' before '&' token
Run Code Online (Sandbox Code Playgroud)

但我不知道为什么会发生这种错误,我不认为原因是编译器指示的.

#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)

c++ header ifstream c++11

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

Goroutine中不包含关键字“ go”的比较

以下代码记录了一个错误:

致命错误:所有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”。

我对此情况有些困惑。提前致谢!

channel go goroutine

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

标签 统计

c++ ×1

c++11 ×1

channel ×1

go ×1

goroutine ×1

header ×1

ifstream ×1