首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

程序调用这两个函数的时侯怎么自己区分该调用哪一个

2012-05-24 
程序调用这两个函数的时侯如何自己区分该调用哪一个?C/C++ codetemplate typename T, int AS const T& O

程序调用这两个函数的时侯如何自己区分该调用哪一个?

C/C++ code
template< typename T, int AS >const T& Octree<T,AS>::operator() ( int x, int y, int z ) const{    return at(x,y,z);}


第二个:
C/C++ code
template< typename T, int AS >T& Octree<T,AS>::operator() ( int x, int y, int z ){    assert( x >= 0 && x < size_ );    assert( y >= 0 && y < size_ );    assert( z >= 0 && z < size_ );    Node** n = &root_;    int size = size_;    while ( size != aggregateSize_ ) {        if (!*n) {            *n = new Branch;        }        else if ( (*n)->type() == BranchNode ) {            size /= 2;            n = &reinterpret_cast<Branch*>(*n)->child(                    !!(x & size), !!(y & size), !!(z & size) );        }        else {            return reinterpret_cast<Leaf*>(*n)->value();        }    }    if (!*n) {        *n = new Aggregate(emptyValue_);    }    --size;    return reinterpret_cast<Aggregate*>(*n)->value(            x & size, y & size, z & size );}


貌似函数名只有const 区别, 那程序调用这两个函数的时侯如何自己区分该调用哪一个?

比如:


C/C++ code
    nodeVal emptyNode(0);    Octree<nodeVal> o(64, emptyNode);o(ix,iy,iz) = nodeVal(x,y,z,gx,gy,gz,vx,vy,vz,k1,k2,k3, ix, iy, iz);


[解决办法]
const对象调用const函数,非const对象调用非const的同名函数。
[解决办法]
正解,Effective C++条款3讲得很详细
探讨

const对象调用const函数,非const对象调用非const的同名函数。

[解决办法]
AS应该是Octree模板类的一个参数吧,但是operator()不一定要用到它

热点排行