为什么我会收到错误? [英] Why am I getting errors?

查看:95
本文介绍了为什么我会收到错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始使用课程,我在学校忘记了我的c ++参考书,所以请你告诉我为什么我的cin语句中出现错误请:



I'm new to using classes and I forgot my c++ reference book at school so could you please tell me why I am getting errors in my cin statements please :)

#include<iostream>

using namespace std;

class Fraction{
public:
	int num1, num2, den1, den2;
	int calnum, calden;
};
	
void add();
void subtract();
void multiply();
void divide();

int main(){
	Fraction calculate;
	cout << "Enter operations";
	cin >> Fraction.num1;
	cin >> Fraction.num2;
	cin >> Fraction.den1;
	cin >> Fraction.den2;
} 

推荐答案

两个问题......

1.你使用的是类(类型) )name Fraction 而不是object(实例)name calculate ...

2。你永远不会初始化计算所以它将为null,无论如何你都会有一些null-reference-exception ...

As Carlo - 理所当然地说,它是C ++,所以不需要单独初始化...
Two problems...
1. You use the class (type) name Fraction instead of object (instance) name calculate...
2. You never initialize calculate so it will be null and you will have some null-reference-exception anyway...
As Carlo - rightfully - stated, it is C++, so no need of separate initialization...


如果你错过了参考书,你不需要感到迷茫。如果您有足够的Internet访问权来提出这个问题,那么您可以直接获得C ++引用和C ++库引用,特别是:

https://msdn.microsoft.com/en-us/library/3bstk3k5.aspx [ ^ ](但请记住,它还包括您可能或许多人不需要的C ++ / CLI, http://en.wikipedia.org/wiki/C%2B%2B/CLI [<一个href =http://en.wikipedia.org/wiki/C%2B%2B/CLItarget =_ blanktitle =New Window> ^ ]),

http://www.cplusplus.com/reference [ ^ ],

http://www.tutorialspoint.com/cplusplus/cpp_references.htm [ ^ ],

http://www.learncpp.com [ ^ ],

http://www.cplusplus.com [ ^ ]。



此外,它可能是比询问这些问题更快,同时更有用,因为当你找到自己需要的东西时,你会学到更多的技能。



-SA
If you are missing your reference book, you don't need to feel lost. If you have enough of Internet access to ask this question, you have everything to get directly to C++ references and C++ libraries references, in particular:
https://msdn.microsoft.com/en-us/library/3bstk3k5.aspx[^] (but remember, it also covers C++/CLI which you may or many not need, http://en.wikipedia.org/wiki/C%2B%2B/CLI[^]),
http://www.cplusplus.com/reference[^],
http://www.tutorialspoint.com/cplusplus/cpp_references.htm[^],
http://www.learncpp.com[^],
http://www.cplusplus.com[^].

Also, it could be faster than asking such questions and more useful at the same time, because, when you find what you need by yourself, you learn more skills.

—SA


这篇关于为什么我会收到错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆