小编ame*_*bey的帖子

简单的 Solidity 合约和脚本出现无效操作码错误

我是 Solidity 和 web3.js 的新手。我正在遵循这里的教程 -

https://medium.com/@mvmurthy/full-stack-hello-world-voting-ethereum-dapp-tutorial-part-1-40d2d0d807c2

构建一个简单的投票 Dapp。我已经使用 npm 在本地 node_modules 文件夹中安装了 ganache-cli、solc 和 web3 版本 0.20.2。Solidity 中的 Voting.sol 合约是:

pragma solidity ^0.4.18;

contract Voting {

  mapping (bytes32 => uint8) public votesReceived;
  bytes32[] public candidateList;

  function Voting(bytes32[] candidateNames) public {
    candidateList = candidateNames;
  }

  function totalVotesFor(bytes32 candidate) view public returns (uint8) {
    return votesReceived[candidate];
  }
}
Run Code Online (Sandbox Code Playgroud)

使用以下名为 vote_main.js 的脚本:

Web3 = require('web3')
web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"))

fs = require('fs')
code = fs.readFileSync('Voting.sol').toString()

solc = require('solc')
compiledCode = solc.compile(code) …
Run Code Online (Sandbox Code Playgroud)

javascript blockchain ethereum solidity web3js

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

错误:请求 '..' 中的成员 '..' ,这是非类类型

我使用 STLpriority_queue并提供一个自定义比较器类,其构造函数接收指向存储优先级的向量的指针,因此 -

#include <iostream>
#include <queue>          // std::priority_queue
#include <vector>         // std::vector

using namespace std;

class CompareReachDist
{
    const vector<float> *reach_dists;
public:
    CompareReachDist(const vector<float> *input)
    {
        reach_dists = input;
    }

    bool operator() (const size_t &l, const size_t &r) const
    {
        return (reach_dists->at(l) > reach_dists->at(r));
    }
};

typedef priority_queue<size_t, vector<size_t>, CompareReachDist> pq;
vector<float> reach_dists;

int main()
{
    pq seeds(CompareReachDist(&reach_dists));
    bool isEmpty = seeds.empty();

  return 0;
}
Run Code Online (Sandbox Code Playgroud)

但是,在编译时出现错误:

error: request for member 'empty' in 'seeds', which is of non-class …
Run Code Online (Sandbox Code Playgroud)

c++ syntax initialization variable-initialization most-vexing-parse

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