copy constructors; why can access private data?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • thomas

    copy constructors; why can access private data?

    guys, I defined a copy constructor like this.

    --code--
    FiveTuple::Five Tuple(const FiveTuple &fv_tuple){
    source_ip_ = fv_tuple.source _ip_;
    dest_ip_ = fv_tuple.dest_i p_;
    source_port_ = fv_tuple.source _port_;
    dest_port_ = fv_tuple.dest_p ort_;
    ip_protocol_ = fv_tuple.ip_pro tocol_;
    }
    --code--

    It works.

    but the source_ip_, dest_ip_, etc are all private;
    How can the copy constructor access private data of fv_tuple directly?
  • Jeff Schwab

    #2
    Re: copy constructors; why can access private data?

    thomas wrote:
    guys, I defined a copy constructor like this.
    >
    --code--
    FiveTuple::Five Tuple(const FiveTuple &fv_tuple){
    source_ip_ = fv_tuple.source _ip_;
    dest_ip_ = fv_tuple.dest_i p_;
    source_port_ = fv_tuple.source _port_;
    dest_port_ = fv_tuple.dest_p ort_;
    ip_protocol_ = fv_tuple.ip_pro tocol_;
    }
    --code--
    >
    It works.
    >
    but the source_ip_, dest_ip_, etc are all private;
    How can the copy constructor access private data of fv_tuple directly?
    Private to the type, not the object.

    Comment

    Working...