非成员方法的原型中const的目的是什么 [英] What is the purpose of a const in the prototype for a non member method
本文介绍了非成员方法的原型中const的目的是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个非成员函数,它有一个原型
const print()const {
可能是什么目的同样的?
I have a non member function , which has a prototype
const print() const{
What could be the purpose of the same?
推荐答案
10月24日下午1:51,parag_p ... @ hotmail.com < parag_p ... @ hotmail.com>
写道:
On Oct 24, 1:51 pm, "parag_p...@hotmail.com" <parag_p...@hotmail.com>
wrote:
我有一个非成员函数,它有一个原型
const print()const {
可能是什么目的?
I have a non member function , which has a prototype
const print() const{
What could be the purpose of the same?
你不能在非成员
函数中使用const,volatile之类的函数修饰符。它不允许你的代码编译。
-Uday Bidkar
You can not use function modifiers like const, volatile on nonmember
functions. It won''t allow your code to compile.
-Uday Bidkar
#include< iostream>
使用namespace :: std;
const void print(){
cout<< "哇"<<结束;
}
int main(){
print();
返回0 ;
}
但是我用g ++ 3.6编译了上面的代码,它对我有用。
没有任何警告。我想我们可能会有误解
-Parag
#include<iostream>
using namespace::std;
const void print () {
cout << " wow "<< endl;
}
int main(){
print();
return 0;
}
But I compile the above with g++ 3.6 and it does work for me.
without any warnings. i think we might have misunderstanding
-Parag
对于方法之后的const修饰符声明我很抱歉。
这不是故意的。我说的是最初的一个
I am sorry about the const modifier declaration after the method.
This was not intended. I am talking about the initial one
这篇关于非成员方法的原型中const的目的是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文