Thursday, 15 March 2012

c++ - Can a class name instead of a namespace be pre-pended to :: for scope resolution? -



c++ - Can a class name instead of a namespace be pre-pended to :: for scope resolution? -

so understand it, when see double colons(abc::xyz) used thing on left namespace , thing on right can function or variable of sort defined in namespace. ex. namespace::bar, namespace::foo()

now, can thing on left class? ex. class::bar, class::foo()

if so, have info on this. can find lots of info of scope resolution pertaining namespaces not when comes classes.

in situation going through rather big project of code individual. code usage trying understand have next line of code...

multi_img::ptr input = imginput::imginput(config.input).execute();

on right imginput::imginput() can found because there namespace imginput can find. on left, multi_img::ptr, there no multi_img namespace in project. there multi_img class contains next line...

typedef boost::shared_ptr<multi_img> ptr;

i believe multi_img::ptr means can not find documentation assumption.

now, can thing on left class?

yes can, , justify consider next example:

#include <iostream> class foo { public: void fun() const { std::cout << "foo:fun()" << std::endl; } }; int main() { foo f; f.foo::fun(); homecoming 0; } demo every class fellow member lies in scope of class.

edit after @cheersandhth.-alf constructive comment:

thus, can access fellow member through object either classical way (e.g., f.fun()) in case you'll have virtual phone call or phone call in illustration (i.e., f.foo::fun()) in case explicitly disambiguate scope of fellow member function @ compile time.

c++ scope

No comments:

Post a Comment