成员函数自定义类型返回'在C ++中没有命名类型'错误

时间:2015-04-24 16:30:36

标签: c++ oop

在我的类中,我使用'using'关键字“bigvalue_t”声明一个类型,并尝试创建一个返回相同类型(to_vector)的函数。我通过gcc返回了这个错误:

 g++ -g -O0 -Wall -Wextra -std=gnu++11 -c bigint.cpp
 bigint.cpp:45:1: error: ‘bigvalue_t’ does not name a type
 bigvalue_t bigint::to_vector (string& strval) {
 ^

以下是我头文件中的类:

class bigint {
  friend ostream& operator<< (ostream&, const bigint&);
private:
  long long_value {};
  using unumber = unsigned long;
  using digit_t = unsigned char;
  using bigvalue_t = vector<digit_t>;
  bool negative;
  bigvalue_t big_value;
  string to_string (unumber& num);
  bigvalue_t to_vector (string& strval);
  using quot_rem = pair<bigint,bigint>;
  friend quot_rem divide (const bigint&, const bigint&);
  friend void multiply_by_2 (unumber&);
  friend void divide_by_2 (unumber&);
public:

  //
  // Ensure synthesized members are genrated.
  //
  bigint() = default;
  bigint (const bigint&) = default;
  bigint (bigint&&) = default;
  bigint& operator= (const bigint&) = default;
  bigint& operator= (bigint&&) = default;
  ~bigint() = default;

  //
  // Extra ctors to make bigints.
  //
  bigint (const long);
  bigint (const string&);

这是我的构造函数和有问题的函数:

bigint::bigint (long that): long_value (that) {
   using digit_t = unsigned char;
   using bigvalue_t = vector<digit_t>;
   if (that < 0) this->negative = true;
   else this->negative = false;
   unumber that_value = that;
   string that_str = to_string (that_value);
   bigvalue_t bignum = to_vector (that_str);
   }

bigvalue_t bigint::to_vector (string& strval) {
   digit_t digi;
   bigvalue_t digivec;
   for (auto it = strval.rbegin(); it != rend; ++i) {
       digi = strval[it];
   digivec.push_back(digi);
   }
  return digivec;
}

任何有关最新情况的想法都会非常感激!它似乎没有拿起我的类型定义。我被允许在没有错误的早期方法中使用我的另一个自定义变量“unumber”,所以这让我摸不着头脑。

1 个答案:

答案 0 :(得分:1)

作为评论中的状态,请使用

bigint::bigvalue_t bigint::to_vector (string& strval)
{
    // body
}

或者从C ++ 11开始

auto bigint::to_vector (string& strval) -> bigvalue_t
{
    // body
}