班级不被承认 [英] Class is not recognized

查看:83
本文介绍了班级不被承认的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

//program
#include<iostream.h>
class student
{
int rollno;
char name[20];
int marks;
public:
student(int rollno,char name[20],int marks);
student(student &s)
{
rollno=s.rollno;
name==s.name;
marks=s.marks;
}
void display()
{
cout<<rollno<<name<<marks;
}
};
void main()
{  str="hka";
student stud1(23,str,100);
student stud2(stud1);
stud2.display();
}



请告诉我在哪里需要更正我的代码..



我尝试了什么:



试图初始化字符串


Pls tell me where i have to correct my code..

What I have tried:

Tried to initialize the string

推荐答案

你必须实现第一个学生构造函数。班级名称以大写字母开头。



答案str变量未定义。否则,请使用 more care 阅读错误消息,并使用谷歌搜索错误编号。大多数情况下它们都是可以理解的。



访问一些教程,如学习CC ++教程,了解有关编程的更多信息,例如代码语法和调试。
You must implement the first student constructor. Class names are starting with a capital letter.

Ans the "str" variable isnt defined. Else read the the error messages with more care and google for the error number. Mostly they are understandable.

Visit some tutorials like the Learn CC++ tutorial for learning more about programming, like code syntax and debugging.


试试这个:



Try this:

//program
#include <iostream>

class student
{
private:
	int rollno;
	char name[20];
	int marks;

public:
	student(int _rollno, const char* _name, int _marks)
	{
		memset(name, 0, 19);
		rollno = _rollno;
		strcpy_s(name, _name);
		marks = _marks;
	}

	student(student &s)
	{
		rollno = s.rollno;
		strcpy_s(name, s.name);
		marks = s.marks;
	}

	void display()
	{
		std::cout << rollno << ", " << name << ", " << marks;
	}
};

void main()
{
	const char *str = "hka\0";
	
	student stud1(23, str, 100);
	student stud2(stud1);
	stud2.display();
}


您使用的是什么编译器? Turboc ++ 3.0?如果是这样,首先放弃它。

cout在std命名空间中。

使用iostream而不是iostream.h,

你需要声明构造函数体

你的str未被声明
What compiler are you using? Turboc++ 3.0? If so, start with ditching it.
cout is in std namespace.
Use iostream not iostream.h,
you need to declare constructor body
Your str is not declared


这篇关于班级不被承认的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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