c++中调用类中函数或者变量,类中的非静态函数调用有两种方式;
一、采用指针
二、声明类的对象
调用类中的静态变量或静态函数,则采用
类::静态变量或函数
#include<iostream>
using namespace std;
class Tests{
public:
void prints();
static void printss();
int a = 0;
};
void Tests::prints(){
cout << "test" << endl;
}
void Tests::printss(){
cout << "test2" << endl;
}
int main(){
//方式一,创建类的对象
Tests *data = new Tests;
data->prints();
//方式二,创建类的对象
Tests().prints();
//方式三, 调用静态函数,不用创建类的对象
Tests::printss();
}