primary-expression ( expression-list )
Point pt; pt( 3, 2 );
// function_call.cpp
class Point
{
public:
Point() { _x = _y = 0; }
Point &operator()( int dx, int dy )
{ _x += dx; _y += dy; return *this; }
private:
int _x, _y;
};
int main()
{
Point pt;
pt( 3, 2 );
}
typedef void(*ptf)();
void func()
{
}
struct S
{
operator ptf()
{
return func;
}
};
int main()
{
S s;
s();//operates as s.operator ptf()()
}
// subscripting.cpp
// compile with: /EHsc
#include <iostream>
using namespace std;
class IntVector {
public:
IntVector( int cElements );
~IntVector() { delete [] _iElements; }
int& operator[]( int nSubscript );
private:
int *_iElements;
int _iUpperBound;
};
// Construct an IntVector.
IntVector::IntVector( int cElements ) {
_iElements = new int[cElements];
_iUpperBound = cElements;
}
// Subscript operator for IntVector.
int& IntVector::operator[]( int nSubscript ) {
static int iErr = -1;
if( nSubscript >= 0 && nSubscript < _iUpperBound )
return _iElements[nSubscript];
else {
clog << "Array bounds violation." << endl;
return iErr;
}
}
// Test the IntVector class.
int main() {
IntVector v( 10 );
int i;
for( i = 0; i <= 10; ++i )
v[i] = i;
v[3] = v[9];
for ( i = 0; i <= 10; ++i )
cout << "Element: [" << i << "] = " << v[i] << endl;
}
Array bounds violation.
Element: [0] = 0
Element: [1] = 1
Element: [2] = 2
Element: [3] = 9
Element: [4] = 4
Element: [5] = 5
Element: [6] = 6
Element: [7] = 7
Element: [8] = 8
Element: [9] = 9
Array bounds violation.
Element: [10] = 10
class-type *operator–>()
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有