Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!feeder.news-service.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Ian Collins Newsgroups: comp.lang.c++ Subject: Re: call member function without object-compile error Date: Wed, 22 Jun 2011 15:55:59 +1200 Lines: 50 Message-ID: <96d7euFmtvU5@mid.individual.net> References: <26f1f45a-7441-411a-942d-d4e70b853922@j14g2000prn.googlegroups.com> <96d4tjFmtvU4@mid.individual.net> <39a31ad8-bfa6-4cf7-a9e0-64192fdb9cdb@h12g2000pro.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net s5EdDg/GcmQQMVVnlb4hZAPgOswI6h/DSZAFPMcn/oAj6IbooE Cancel-Lock: sha1:xvLGqL5LEAzYH+BaLr3lRjR5MLI= User-Agent: Mozilla/5.0 (X11; U; SunOS i86pc; en-US; rv:1.9.2.9) Gecko/20101021 Lightning/1.0b2 Thunderbird/3.1.4 In-Reply-To: <39a31ad8-bfa6-4cf7-a9e0-64192fdb9cdb@h12g2000pro.googlegroups.com> Xref: x330-a1.tempe.blueboxinc.net comp.lang.c++:7046 On 06/22/11 03:28 PM, eric wrote: > On Jun 21, 8:12 pm, Ian Collins wrote: >> On 06/22/11 03:01 PM, eric wrote: >> >>> Dear c++ advancer: >>> I have a simple c++ file, which is I copy and try to test from a >>> book (C++ Primer 3rd Ed, by Stanley B. Lippman and Josee Lajoie, >>> around page 904, chapter 17.3 Base Class Member Access) >>> the following is my program: >> >> >> >>> ----------------------------- >>> the following is my g++ result(4.5.2) >>> -------------------- >>> eric@eric-laptop:~/CppPrimer3$ g++ p904.cpp >>> p904.cpp: In member function bool NameQuery::compare0(const Query*) : >>> p904.cpp:36:24: error: std::vector > >>> Query::_loc is protected >>> p904.cpp:88:30: error: within this context >>> p904.cpp: In function int main() : >>> p904.cpp:96:30: error: cannot call member function bool >>> NameQuery::compare0(const Query*) without object >>> eric@eric-laptop:~/CppPrimer3$ >>> -------------------------------------- >>> I just like to know how to fix (88:30) and (96:30) >>> thanks a lot in advance, Eric >> >> For the protected access, provide a public member function to return the >> vector size. >> >> For the call, you have to have an instance of NameQuery to call a >> non-static member function. >> >> As a general point, names starting with leading underscores may clash >> with names used by your implementation. > > Thanks your reply and suggestion > but after I change leading underscore to a_ (add an "a" in front of > all _variablename) > my g++ still response name error : Cann't call memeber function > without object on (88:30 and 96:30) /* try by yourself */ > so > still need any advancer's help and suggestion and thanks a lot in > advance, Eric What about the other two suggestion to fix your actual problem? -- Ian Collins