错误改进typedef obj的使用 [英] error-improve use of typedef obj

查看:129
本文介绍了错误改进typedef obj的使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在此c ++程序中出现错误改进了typedef obj 的使用.
这是交换程序.
请帮帮我吗?

并说明错误以及如何清除此错误.

I have error improve use of typedef obj in this c++ program.
This is swapping a program.
Please help me?

And explain the error and how to clear this error.

#include
#include

class swap
{
int a,b;
public:
void getdata(void);
void change(void);
void display(void);
};

void swap :: getdata(void)
{
cout<<" enter the a value: ";
cin>>a;
cout<<"enter the b value: ";
cin>>b;
}

void swap :: change(void)
{
a = a+b;
b = a-b;
a = a-b;
}

void swap :: display(void)
{
cout<<"a value: "<<"\n";
cout<<"b value: "<<"\n";
}

void main()
{
clrscr();
class obj;
obj.getdata();
obj.display();
getch();
}

推荐答案

定义swap类变量时,使用class关键字是错误的. 代替使用
You use of the class keyword is wrong when defining a swap class variable.
Instead of using
void main()
{
	clrscr();
	class obj;
	obj.getdata();
	obj.display();
	getch();
}


使用


use

void main()
{
	clrscr();
	swap obj;
	obj.getdata();
	obj.display();
	getch();
}



您可以阅读以下简短教程,以增加对类和变量的了解:
类(I) [变量.数据类型. [^ ]



You can read these short tutorials to increase your knowledge about classes and variables:
Classes (I)[^]
Variables. Data Types.[^]


可能您在不使用临时(堆栈)变量的情况下就将两个赋值分配给了整数,否则您将诚实地使用临时变量而无需四处走动.

这是一个非常简单的经典练习,因此每个人都应该在不阅读任何内容的情况下找到解决方案,但是当然是基于简单位算术的知识.


您的结果虽然正确,但并不优雅.有一种简单且通用的方法可以交换任何两个位模式,而不使用数字类型的算术并且不使用任何临时存储值.
您的问题是语法.使用AndréKraak的建议.
[END EDIT]

对不起,我不想告诉您解决方案,否则它对您没有用,但会欺骗那些诚实地自己解决任务的人.

—SA
Probably you got an assignment two swap to integers without using temporary (stack) variable, otherwise you would honestly use a temporarily variable with no need to goof around.

This is a classical exercise which is very simple, so everyone is supposed to find the solution without reading anything, but of course based on knowledge of simple bit arithmetic.


You result is correct though, but not elegant. There is a simple and universal way to swap any two bit patterns not using arithmetic of numeric types and not using any temporary storage for a value.
Your problem is the syntax. Use the advice by André Kraak.
[END EDIT]

Sorry, I don''t want to tell you the solution, otherwise it would be not useful to you but would be cheating against people who honestly solve their assignment by themselves.

—SA


这篇关于错误改进typedef obj的使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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