/ MYOJ /

记录详情

Compile Error

foo.cc: In member function 'highPre& highPre::operator+(highPre&)':
foo.cc:10:17: error: no matching function for call to 'highPre::highPre()'
   10 |         highPre c;
      |                 ^
foo.cc:37:5: note: candidate: 'highPre::highPre(std::string&)'
   37 |     highPre(string & b){
      |     ^~~~~~~
foo.cc:37:5: note:   candidate expects 1 argument, 0 provided
foo.cc:6:7: note: candidate: 'highPre::highPre(const highPre&)'
    6 | class highPre{
      |       ^~~~~~~
foo.cc:6:7: note:   candidate expects 1 argument, 0 provided
foo.cc:6:7: note: candidate: 'highPre::highPre(highPre&&)'
foo.cc:6:7: note:   candidate expects 1 argument, 0 provided
foo.cc:12:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |             for(int i = 0; i < a.size() - p.a.size();i++){
      |                            ~~^~~~~~~~~~~~~~~~~~~~~~~
foo.cc:13:21: error: 'class std::vector<int>' has no member named 'pushback'; did you mean 'push_back'?
   13 |                 p.a.pushback(0);
      |                     ^~~~~~~~
      |                     push_back
foo.cc:17:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |             for(int i = 0; i < p.a.size() - a.size();i++){
      |                            ~~^~~~~~~~~~~~~~~~~~~~~~~
foo.cc:18:19: error: 'class std::vector<int>' has no member named 'pushback'; did you mean 'push_back'?
   18 |                 a.pushback(0);
      |                   ^~~~~~~~
      |                   push_back
foo.cc:21:20: error: declaration of 'int p' shadows a parameter
   21 |         int k = 0, p = 0;
      |                    ^
foo.cc:22:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |         for(int i = 0; i < a.size(); i++){
      |                        ~~^~~~~~~~~~
foo.cc:23:24: error: 'b' was not declared in this scope
   23 |             k = a[i] + b[i] + p;
      |                        ^
foo.cc:28:17: error: 'class std::vector<int>' has no member named 'pushback'; did you mean 'push_back'?
   28 |             c.a.pushback(k);
      |                 ^~~~~~~~
      |                 push_back
foo.cc:30:16: warning: reference to local variable 'c' returned [-Wreturn-local-addr]
   30 |         return c;
      |                ^
foo.cc:10:17: note: declared here
   10 |         highPre c;
      |                 ^
foo.cc: In constructor 'highPre::highPre(std::string&)':
foo.cc:39:15: error: 'class std::vector<int>' has no member named 'pushback'; did you mean 'push_back'?
   39 |             a.pushback(b[i]-'0');
      |               ^~~~~~~~
      |               push_back
foo.cc: In function 'int main()':
foo.cc:47:16: error: 'highPre::highPre(std::string&)' is private within this context
   47 |     highPre A(a);
      |                ^
foo.cc:37:5: note: declared private here
   37 |     highPre(string & b){
      |     ^~~~~~~
foo.cc:48:16: error: 'highPre::highPre(std::string&)' is private within this context
   48 |     highPre B(b);
      |                ^
foo.cc:37:5: note: declared private here
   37 |     highPre(string & b){
      |     ^~~~~~~
foo.cc:50:21: error: 'highPre& highPre::operator+(highPre&)' is private within this context
   50 |     highPre C = A + B;
      |                     ^
foo.cc:9:14: note: declared private here
    9 |     highPre& operator+(highPre& p){
      |              ^~~~~~~~
foo.cc:51:11: error: 'void highPre::put()' is private within this context
   51 |     C.put();
      |           ^
foo.cc:32:10: note: declared private here
   32 |     void put(){
      |          ^~~
foo.cc:52:5: error: return-statement with no value, in function returning 'int' [-fpermissive]
   52 |     return;
      |     ^~~~~~
[Hydro](https://hydro.ac)提供评测服务

代码

#include<iostream>
#include<vector>
#include<string>
using namespace std;

class highPre{
    vector<int> a;
    
    highPre& operator+(highPre& p){
        highPre c;
        if(this->a.size()> p.a.size()) {
            for(int i = 0; i < a.size() - p.a.size();i++){
                p.a.pushback(0);
            }
        }
        else if (a.size()< p.a.size()) {
            for(int i = 0; i < p.a.size() - a.size();i++){
                a.pushback(0);
            }
        }
        int k = 0, p = 0;
        for(int i = 0; i < a.size(); i++){
            k = a[i] + b[i] + p;
            if(k>=10){
                p = k/10;
                k -= 10;
            }
            c.a.pushback(k);
        }
        return c;
    }
    void put(){
        for (int i = a.size()-1; i >=0; i--){
            cout << a[i];
        }
    }
    highPre(string & b){
        for(int i = b.size()-1; i>= 0 ;i--){
            a.pushback(b[i]-'0');
        }
    }
};

int main(){
    string a,b ;
    cin >> a >> b;
    highPre A(a);
    highPre B(b);
    
    highPre C = A + B;
    C.put();
    return;
}

信息

递交者
类型
自测
题目
P1020 [7FOJ]高精度加法
语言
C++
递交时间
2022-06-17 16:15:52
评测时间
2022-06-17 16:15:52
评测机
分数
0
总耗时
0ms
峰值内存
0 Bytes