Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 错误:使用友元函数时参数太少,无法运行_C++ - Fatal编程技术网

C++ 错误:使用友元函数时参数太少,无法运行

C++ 错误:使用友元函数时参数太少,无法运行,c++,C++,问题是创建一个名为ACCOUNTS的类,该类带有一个read函数来接受销售和购买,然后创建一个friend函数来打印要支付的总税额。我尝试过这样做,但我一直得到一个错误,函数read和tottax的参数太少。我能纠正什么 #include<stdio.h> #include<iostream> using namespace std; class ACCOUNTS { public: ACCOUNTS(

问题是创建一个名为ACCOUNTS的类,该类带有一个read函数来接受销售和购买,然后创建一个friend函数来打印要支付的总税额。我尝试过这样做,但我一直得到一个错误,函数read和tottax的参数太少。我能纠正什么

#include<stdio.h>
    #include<iostream>
    using namespace std;
    class ACCOUNTS
    {   
        public:
        ACCOUNTS(){sales=0,purchase=0;}
        private:
            int sales,purchase;


        friend void tottax(ACCOUNTS &sfo);
        friend void read(ACCOUNTS &sfo);
    };
        void read(ACCOUNTS &sfo)
        {
            cout<<"Enter saleamt : \n";
            cin>>sfo.sales;
            cout<<"Enter purchaseamt : \n";
            cin>>sfo.purchase;
        }
        void tottax(ACCOUNTS &sfo)
        {
            int tax=(sfo.sales-sfo.purchase)*(4/100);
            cout<<"\nTax : "<<tax;
        }
        int main()
        {
            read();
            tottax();
            return 0;
        }
《证券及期货条例》规定的账户无效;嘿,我是一个函数,它不会返回一个位void作为返回类型,但我需要调用ACCOUNTS类型的对象。所以你要么给我一个,要么我不执行

大体上,您是通过以下方式调用tottax:tottax 也就是说: 亲爱的编译器您能调用函数tottax吗?这个函数不带任何参数?编译器查看您的r源代码,并试图找到类似于:void totax{…}的东西,它显然不存在,因为您编写的totax的唯一版本只接受一个参数

问题是,tottax只需要一个参数。这就是编译器抱怨的原因

再想想:tottax计算与账户相关的东西。如果你不提供一个,它将如何计算


函数read也是如此。

dots;与税务账户和sfo匹配?是!是的。我的意思是,我正在调用右主体中的函数tottax;还有同样的问题tottax想要的参数在哪里?我不明白。。。为什么tottax需要一个参数。我是Cpp和OOP概念的初学者。。。忘了提了。我参加calsses后的第一个项目