静态成员函数

C++ 静态成员函数调用非静态成员函数方法 #include #include class Class; typedef struct { Class *pClass; int x; int y; }ParaNode; class Class { public: int i; void Seti(int index) { i=index; } bool SaneCommandSASTest(int x,int 阅读详情

      静态成员函数和静态数据成员一样,它们都属于类的静态成员,它们都不是对象成员。静态成员函数不接受隐含的this自变量。

规则:1、无法访问自己类的非静态成员因此,对静态成员的引用不需要用对象名。

      2、如果静态成员函数中要引用非静态成员时,可通过对象来引用。下面通过例子来说明这一点。(这段程序有问题)

using System;
namespace test
{
 class M
 {
  public M(int a) { A=a; B+=a;}
  public static void f1(M m)
  {
   cout<<"A="<< cout<<"B=";
  }
  private int A;
  private static int B;
  private M()
  {
   B = 0;
  }
 };

 void Main()
{
 //int M::B=0;
 M P(5),Q(10);
 M::f1(P); file://调用时不用对象名
 M::f1(Q);
}
}

 

执行结果:A=5,B=5

                    A=10,B=15

insightface scrfd人脸检测测试 pip install mmdet 自动安装mmcv win10上可以,服务器上没成功 阅读详情

相关推荐

RISC-V— 架构基础知识学习

蜂鸟 E200 系列是一个开源的RISC-V 处理器。蜂鸟 E200 系列由中国大陆研发团队开发,用户能够轻松与开发人员取得交流和支持。RI蜂鸟 E200 处理器研发团队拥有在国际一流公司多年开发处理器的经验,使用稳健的Verilog 2001 语法编写的可综合 RTL 代码,以工业级标准进行开发。蜂鸟 E200 的代码为人工编写,添加丰富的注释且可读性强,非常易于理解。

deilt 1万+

静态函数调用

静态函数 #include <iostream.h> class Point { public: void output()//非静态成员函数 { } static void init()//静态成员函数 { } }; 调用1:非静态成员函数和非静态成员属于对象的方法和数据,也就是先产生类的对象,然后通过类的对象去引用。 voi...

qq_36633275的博客 5305

QCC308X/518X/309X加LDAC解码

QCC308X/518X/309X加LDAC解码。

Alex_886的博客 6609

C++ static静态成员静态函数,语法+示例,超详细!!

C++ static静态成员静态函数,语法+示例,超详细!!

ken2232的博客 4万+

Autodesk全家桶怎么选?AutoCAD、Revit、Fusion 360等7款软件超全对比指南

本文深入对比了Autodesk旗下七款核心软件(AutoCAD、Revit、Inventor、Fusion 360、Maya、3ds Max、Forge)的核心定位与适用场景。针对建筑、制造、创意设计等不同专业需求,提供精准的选型指南,帮助用户根据自身工作流(如二维绘图、BIM协同、产品开发、影视动画)选择最匹配的工具,避免资源浪费并提升效率。

stone的博客 434

最新Docker GPU支持全解析:为什么nvidia-smi能用但PyTorch找不到CUDA?

本文深入解析了Docker容器中nvidia-smi命令可用但PyTorch无法调用CUDA的根本原因。关键在于默认配置仅暴露了GPU的utility管理能力,而CUDA计算所需的compute能力未被激活。通过正确设置NVIDIA_DRIVER_CAPABILITIES环境变量为compute,utility,并配合--gpus参数,即可解决此问题,确保AI训练等任务顺利进行。

convnet3designer的博客 239

静态成员函数 与 静态数据成员

面对对象的static-----(静态成员函数 与 静态数据成员)

孤云出岫, 去留一无所系. 朗镜悬空,静躁两不相干. 615

uniapp - [微信小程序] 实现点击预览各种文件 pdf文档、视频mp4、mp3音乐、图片图像、word/excel/ppt 等,uniapp小程序文件预览功能(详细示例代码,一键复制开箱即用)

uniapp,uniapp微信小程序,支付宝小程序平台端,uniapp实现文件在线预览,uniapp微信小程序怎么实现预览视频mp4,mp3音乐,图片,office文档,小程序平台如何在线预览word/excel/ppt文档,uniapp实现小程序端的文件查看功能,uniapp小程序端实现pdf文件预览,uniapp纯前端预览PDF、DOC、DOCX、图片、视频,uni-app文档、图片预览查看,uniapp文档预览功能,uniapp小程序端文件预览,uniapp小程序平台纯前端解析word,pdf,xls

✅ 精选推荐文章 1万+

C++ 1.5.1静态数据成员 静态成员函数

1.静态数据成员 每个类只有一个静态数据成员副本,它由该类的所有对象共同维护和使用。 注意: (1)声明时,使用static关键字。 (2)必须初始化,且一定要在类外进行。初始化形式: <类型标识符><类名>::<静态数据成员名>=<值> (3)静态数据成员属于类,不属于任何一个对象,在类外可通过类名引用。 <类名>::<静态数据成员名> (4)当静态数据成员被声明为私有成员时,只能在类内直接引用它,在类外无法引用。 被声明为公有成员时

weixin_45733227的博客 357

Python 爬虫实战:爬取电商平台商品信息(价格 / 销量 / 评价)

摘要:本文详细介绍基于Python的电商商品信息爬取技术方案,以京东商品详情页为例,对比分析静态(BeautifulSoup)和动态(Selenium)两种爬取方式的实现逻辑。静态爬取适合获取基础信息,而动态爬取可解决JS渲染数据的获取问题。文章包含完整的代码实现、反爬规避策略及数据存储方案,涵盖商品名称、价格、销量、评价等核心数据提取。同时强调爬虫的合规使用,提供扩展方向建议,为电商数据采集提供实用技术参考。

2503_91057718的博客 2021

【案例讲解】LVGL关于旋转的配置

在实现项目中,因为横竖屏的关系,需要对其做90度的旋转。配置旋转时发现一些局部刷新控件,旋转后效果不对。异常图标正常图标。

Bigan(安)的博客 4284

c++静态成员函数的引用

#include #include using namespace std; class Student { public: Student() {total++;} static void DispTotal()//定义静态数据成员 { cout<<“Students’ number is:”<<total<<endl; //静态成员函数中只引用静态数据成员 } private: string name; int score; static int total;//

spursping的博客 810

宇树科技嵌入式面试题及参考答案(春晚机器人的公司)

内存对齐是指在内存中为数据对象分配存储空间时,按照一定的规则将数据存储在特定的地址上,以提高内存访问效率。不同的数据类型在内存中都有其特定的对齐要求,例如,int类型通常要求 4 字节对齐,double类型通常要求 8 字节对齐。这意味着数据的存储地址必须是其对齐字节数的整数倍。如果不进行内存对齐,处理器在访问数据时可能需要进行多次内存访问,从而降低了访问效率。指令可以用于控制结构体内存布局,它允许程序员指定结构体成员的对齐方式。其基本用法是在结构体定义之前使用来指定对齐字节数n,其中n。

大模型大数据攻城狮的专栏 3225

【C++】静态成员函数 ( 静态成员函数概念 | 静态成员函数声明 | 静态成员函数访问 | 静态成员函数只能访问静态成员 )

一、静态成员函数简介 1、静态成员函数概念 2、静态成员函数声明 3、静态成员函数访问 4、静态成员函数只能访问静态成员 二、代码示例 - 静态成员函数

让 学习 成为一种 习惯 ( 韩曙亮 の 技术博客 ) 1万+

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

C++ 静态成员函数

成员函数也可以定义为静态的,在类中声明函数的前面加static就成了静态成员函数,例如: //定义静态成员函数; static long long get_number(){ return number; } 和静态成员变量一样,静态成员函数是类的一部分,而不是对象的一部分。如果要在类外调用公用的静态成员函数,要用类名和域运算符“::”,例如: student::get_number(); 静态成员变量和静态成员函数,是属于类。那么,当用类...

LC的专栏 1万+

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

C++静态成员函数

一点睛 与静态数据成员不同,静态成员函数的作用不是为了对象之间的沟通,而是为了能处理静态数据成员。 静态成员函数没有this指针。既然它没有指向某一对象,也就无法对一个对象中的非静态成员进行默认访问(即在引用数据时不指定对象名)。 静态成员函数和非静态成员函数的根本区别:非静态成员函数有this指针,而非静态成员函数没有this指针。由此决定了静态成员函数不能访问本类中的非静态成员。 静...

实践求真知 9327

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

静态成员函数与非静态成员函数的区别

先放上几个小例子 1、static 修饰成员变量 静态变量,是在编译阶段就分配空间,对象还没有创建时,就已经分配空间。 静态成员变量必须在类中声明,在类外定义。 静态数据成员不属于某个对象,在为对象分配空间中不包括静态成员所占空间。 class Data { public: int num;//普通成员变量 static int data;//静态成员变量(类内声明) }; //定义的时候 不需要加static int Data::data=100;//类外定义+初始化 void test

zhengbudong的博客 5730

静态成员函数和非静态成员函数的区别

静态成员函数和非成员函数的区别 从知乎上看到一个问题,看得我怀疑人生,咬牙切齿,如下图: 对于面试官的解释,把我整蒙圈了;于是自己写代码验证如下: #include<iostream> using namespace std; class A { public: static int func1() { cout << "11" << endl; return 0; } void func2() { cout << "MM" <

doubleintfloat的博客 2361

c++ ——静态成员变量和静态成员函数

c++ 静态成员变量用static 关键字来声明,是整个类的数据成员,其存储不占用某个具体对象的空间,其存储在静态存储区。 c++ 静态成员函数用static 关键字来声明,用于处理静态成员变量,可以用类名来调用,也可以用对象名来调用。 测试代码: #include <iostream> using namespace std; class Point{ public: Po...

夜风的博客 3643

静态成员函数 不能访问非静态成员函数

和静态数据成员一样,静态成员函数是类的一部分,而不是对象的一部分。如果要在类外调用公用的静态成员函数,要用类名和域运算符“∷”。如 Box∷volume( ); 实际上也允许通过对象名调用静态成员函数,如 a.volume( ); 但这并不意味着此函数是属于对象a的,而只是用a的类型而已。 静态成员函数的作用是为了能处理静态数据成员。 可以说,静态成员函数与非静态成员函数的根本区别是:

yanxuetao的专栏 2438

静态成员函数的作用

静态成员函数主要为了调用方便,不需要生成对象就能调用。 比如: class X { public: void MethodA(); static void MethodB(); } 此时MethodB可以直接调用,X::MethodB(); MethodA必须先生成类对象才能调用,X x; x.MethodA(); 函数的行为对所有派生类都一致时,可以声明为静态。 静态成员函数的作用基本上相当于:一个带有命名空间的全局函数。 如一个数学类定义了一些函数 都可以声明伪静态的 Ma...

qq_20853741的博客 4574

【C++】静态成员函数

类中的成员函数,若未使用类中的成员变量,则可声明为静态成员函数,函数声明前加上static关键字。静态成员函数不属于对象,属于类。静态成员函数与成员函数用法上的主要不同为:调用静态成员函数时,不需要实例化一个对象。只需要使用类名命名空间标识符) 加函数名即可调用。

Loup&卡普的博客 4623

静态成员函数详解

在类中,static 除了可以声明静态成员变量,还可以声明静态成员函数。普通成员函数可以访问所有成员(包括成员变量和成员函数),静态成员函数只能访问静态成员。 编译器在编译一个普通成员函数时,会隐式地增加一个形参 this,并把当前对象的地址赋值给 this,所以普通成员函数只能在创建对象后通过对象来调用,因为它需要当前对象的地址(this指针就是当前对象的地址)。而静态成员函数可以通过类来直接调...

qq_41961154的博客 6701

静态成员函数引用非静态成员

C++会区分两种类型的成员函数:静态成员函数和非静态成员函数。这两者之间的一个重大区别是,静态成员函数不接受隐含的this自变量。所以,它就无法访问自己类的非静态成员。       在某些条件下,比如说在使用诸如pthread(它不支持类)此类的多线程库时,就必须使用静态的成员函数,因为其地址同C语言函数的地址兼容。这种铜限制就迫使程序员要利

朱胜本的专栏 2870
上一篇: 静态构造函数【转载】
下一篇: 问题
ajuntu
博客等级 码龄21年 3粉丝 26原创
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值