From 53455164505621447 X-Google-Thread: f78e5,79ca29fdef991a75,start X-Google-Attributes: gidf78e5,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local01.nntp.dca.giganews.com!nntp.speakeasy.net!news.speakeasy.net.POSTED!not-for-mail NNTP-Posting-Date: Mon, 19 Mar 2007 11:50:14 -0500 Return-Path: X-Authentication-Warning: mulga.csse.unimelb.edu.au: fjh set sender to devnull@stump.algebra.com using -f X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov) X-Original-To: std-c++@mailman.ucar.edu Delivered-To: std-c++@mailman.ucar.edu From: marwan.taher@gmail.com Newsgroups: comp.std.c++ Subject: Address of member in class scope Organization: http://groups.google.com Message-ID: <1174158249.879833.103950@p15g2000hsd.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Complaints-To: groups-abuse@google.com User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; YPC 3.2.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727),gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: p15g2000hsd.googlegroups.com; posting-host=81.159.219.235; posting-account=YENOAw0AAACkiwlWOTwtWpwWpvhYlYqy X-Virus-Scanned: amavisd-new at ucar.edu X-Virus-Scanned: amavisd-new at csse.unimelb.edu.au Approved: Fergus Henderson , moderator of comp.std.c++ X-Virus-Scanned: amavisd-new at csse.unimelb.edu.au Date: Mon, 19 Mar 2007 11:41:49 CST Lines: 51 NNTP-Posting-Host: 65.182.171.162 X-Trace: sv3-WfBFWYm6GbDSwo69bwouEELLgmfTXwitLgB1pYh0B79ud+p8qUEmfyrJ1LReouf4/uWOUmBD9YFAyV6!1UE0B17FgwJEpnxwVPqwPmsUWc+56NqBZmF3TdEpOGwixAeQBSDSnbwfl1jOkf0fjUrl6zG2VTSE!hI2prrLjr1fnmpb/3qErQ4XyUswuqf+o2WUoHjbW2t0= X-Complaints-To: abuse@speakeasy.net X-DMCA-Complaints-To: abuse@speakeasy.net X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.34 Xref: g2news1.google.com comp.std.c++:8085 Can someone tell me why the following code won't compile? I am taking the address of a class member within the class's declaration. This works for a pointer to member function, but fails for a pointer to data member. Is my compiler at fault? Or does the standard explicitly forbid this? struct Example { // Template that takes a pointer to member function template struct Command { void Set(Example& example, int value) { (example.*member) (value); } }; // Template that takes a pointer to data member template struct Property { void Set(Example& example, int value) { (example.*member) = value; } }; int value_; Example() : value_(0) {} int Get() const { return value_; } void Set(int value) { value_ = value; } // Can take an address of member function Command<&Example::Set> Setter; // compiles... // Can NOT take an address of data member //Property<&Example::value_> Value; // !!! WILL NOT COMPILE !!! // Can take an address of data member inside a function void SetValue(int value) { Property<&Example::value_> Value; // compiles... Value.Set(*this, value); } }; --- [ comp.std.c++ is moderated. To submit articles, try just posting with ] [ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ] [ --- Please see the FAQ before posting. --- ] [ FAQ: http://www.comeaucomputing.com/csc/faq.html ]