00问答网
所有问题
当前搜索:
数据成员和函数成员
在C++里,什么是类的
数据成员
?什么是类的
成员函数
?
答:
类的
数据成员
:就是类中的一个实例变量 类的
成员函数
:就i是类中的一个实例函数 class demo{ public :void print();//类的成员函数 int age;//类的数据成员 };希望对你有用...
什么叫做静态
数据成员
答:
静态的意思是跟这个类的对象实例没关系,是类范围的,一个类可以生成多个对象,但只有一份静态数据成员。普通
函数成员
会隐式传递一个this指针,指向调用这个函数的对象;而静态函数成员不包括这个指针,所以在静态
成员函数
内不能使用非静态的
数据成员和函数
。问题四:什么是 静态数据成员 静态函数成员 静态...
...
以及
若干
成员函数
。同时编写主函数使用这个类,实
答:
include<stdio.h> include<xstring> include <WTypes.h> class CStudent { public://构造
函数
CStudent();//重载构造 CStudent(LPSTR szName, byte byAge, int nID);//析构函数 ~CStudent();protected:LPSTRm_szName;//学生姓名 bytem_byAge;//学生年龄 intm_nID;//学生学号 //功能函数...
...一个
数据成员和
一个整型静态数据成员让构造
函数
初始化数据成员并把...
答:
public class Data{ static int staticNum=0;private int num;public Data(){ this.num =0;staticNum ++;System.out.println("构造
函数
调用后: " + staticNum);} public void dm(){ staticNum--;System.out.println("dm()调用后: " + staticNum);} public static void main( String ...
设计一个点类,其中包括一对坐标
数据成员
、一个求两点之间距离的友元
函数
...
答:
include <cmath> using namespace std;class Point //Point类定义 { public: //外部接口 Point(int xx=0, int yy=0) {X=xx;Y=yy;} int GetX() {return X;} int GetY() {return Y;} friend float fDist(Point &a, Point &b); //友元
函数
声明 private: //私有
数据成员
int X,Y...
...个
数据成员
有学号、姓名、年龄,
以及
若干
成员函数
。
答:
include<iostream> include<string.h> using namespace std;class student { private:int stuNo;char name[20];int age;public:student(){} student(int stuNo,char *s,int age){ this->stuNo = stuNo;this->age = age;strcpy(this->name,s);} int getStuNo(){ return this->stuNo;}...
定义一个类时,除了
数据成员
外,是不是一定要定义一个
成员函数
,求详细解 ...
答:
答:不一定,也可以只定义
成员函数
而没有成员变量。但从良好程序设计的角度来看,一个具有良好封装性的类,至少要为调用者提供get/set方法(获取/设置成员变量值的办法)。
java定义一个点类(point),包含x,y坐标
数据成员
,显示
函数
(show)和计算...
答:
import java.lang.Math.*;class point { int x;int y;void show(){ //don't know the purpose for this one.} double getarea(){ return Math.sqrt(y*y + x*x);} } class circirl extends point { int r;double getarea(int r){ return (3.14*r*r);} } public class line {...
基类:Person,
数据成员
:姓名 name;
成员函数
:display()。 由基类派生Stude...
答:
include <string> include <iostream> using namespace std;class Person { public:Person (char* name) : name (name) {} virtual void display ();private:string name;};void Person::display (){ cout << "name:" << name << endl;} class Student : virtual public Person { public:...
java定义一个点类(point),包含x,y坐标
数据成员
,显示
函数
(show)和计算...
答:
Class Point{public int x;public int y;public Point(){}public void show(){}public int getarea(){}}Class Circle extends Point{public int r;public Circle(){}public int getarea(){return r*r;}}Class Line{public Point a=null;public Point b=null;public Line(int ax,int ay,int...
<涓婁竴椤
1
2
3
4
5
6
7
8
9
10
涓嬩竴椤
灏鹃〉
其他人还搜