#include <iostream> #include <iostream> #include <string> class test{ public: test(const std::string _domain,const std::string _interface,const std::string _instance); private: std::string domain_; std::string interface_; std::string instance_; friend std::ostream &operator<<(std::ostream &_out, const test &_address); }; test::test(const std::string _domain,const std::string _interface,const std::string _instance) { // TODO: handle error situation (_address is no valid CommonAPI address) domain_ = _domain; interface_ = _interface; instance_ = _instance; } std::ostream & operator<<(std::ostream &_out, const test &_address) { _out << _address.domain_ << ":" << _address.interface_ << ":" << _address.instance_; return _out; } int main(){ test t("a","b","c"); std::cout<<t<<std::endl; return 0; }
ygy@ygy-VirtualBox:~/work/tmp$ g++ b.cpp ygy@ygy-VirtualBox:~/work/tmp$ ./a.out a:b:c