传递Map Reference作为参数的难度,C ++

时间:2014-12-10 18:21:25

标签: c++ arguments maps

我很难将地图作为参数传递给函数。这是我的.h文件:

#ifndef SELL_H
#define SELL_H

#include "Move.h"
#include "Good.h"
#include <map>
#include "Stack.h"
#include <string>

/* If the card being sold is Precious, two cards must be sold                                                                                                                      
   If the card being sold is Good, one card must be sold                                                                                                                           
   All cards being sold must be of the same type                                                                                                                                   
*/

class Sell: public Move
{
 public:
  Sell(Pile *, Pile *, std::vector<int>, bool);
  bool isValid();
  void execute(std::map<std::string, Stack>&);

};

#endif

这是我的.cpp文件:

#include "Sell.h"
#include "Pile.h"
#include "Move.h"
#include <map>
#include <iostream>
#include "Stack.h"
#include <string>

Sell::Sell(Pile *from, Pile *to, std::vector<int> moving, bool inFlag):
  Move(from, to, moving, inFlag) { }

bool Sell::isValid()
{
  Pile outPile;

  if (from->isEmpty())
    return false;

  outPile = from->babyPile(out);

  if (outPile.isEmpty())
    return false;

  if (outPile.count() < outPile.at(1)->minSale())
    return false;

  // All cards for a sale must be the same                                                                                                                                         
  if (!outPile.isSame())
    return false;

  // If all tests are passed                                                                                                                                                       
  return true;
}

void Sell::execute(std::map<std::string, Stack>& stacks) {

  int size = out.size();
  std::string type = from->returnTypeAt(out.at(0));

  for (int i = 0; i < size; i++)
    from->remove(out.at(i) - i);

  stacks[type].remove(size);

}

我收到一个很长的错误:

In file included from /usr/include/c++/4.8.2/bits/stl_map.h:63:0,
                 from /usr/include/c++/4.8.2/map:61,
                 from Sell.h:7,
                 from Sell.cpp:1:
/usr/include/c++/4.8.2/tuple: In instantiation of ‘std::pair<_T1, _T2>::pair(std::tuple<_Args1 ...>&, std::tuple<_Args2 ...>&, std::_Index_tuple<_Indexes1 ...>, std::_Index_tuple<_Indexes2 ...>) [with _Args1 = {const std::basic_string<char, std::char_traits<char>, std::allocator<char> >&}; long unsigned int ..._Indexes1 = {0ul}; _Args2 = {}; long unsigned int ..._Indexes2 = {}; _T1 = const std::basic_string<char>; _T2 = Stack]’:............
Sell.cpp:43:14:   required from here
/usr/include/c++/4.8.2/tuple:1088:70: error: no matching function for call to ‘Stack::Stack()’
         second(std::forward<_Args2>(std::get<_Indexes2>(__tuple2))...)
                                                                      ^
/usr/include/c++/4.8.2/tuple:1088:70: note: candidates are:
In file included from Sell.h:8:0,
                 from Sell.cpp:1:
Stack.h:18:3: note: Stack::Stack(std::string)
   Stack(std::string);
   ^
Stack.h:18:3: note:   candidate expects 1 argument, 0 provided
Stack.h:8:7: note: Stack::Stack(const Stack&)
 class Stack {
       ^
Stack.h:8:7: note:   candidate expects 1 argument, 0 provided
make: *** [Sell.o] Error 1

任何帮助将不胜感激。我不确定如何通过论证。感谢。

0 个答案:

没有答案