于是写了下面这个类,
class Point {
private:
int m_x;
int m_y;
public:
Point(int x,int y) {
m_x = x;
m_y = y;
}
Point(const Point& pt) {
m_x = pt.get_x();
m_y = pt.get_y();
}
~Point() {};
int get_x(){
return m_x;
}
int get_y(){
return m_y;
}
};
不等写完,编译试试。一编译竟然有错误,提示是
main.cpp:12: error: passing ‘const Point’ as ‘this’ argument of ‘int Point::get_x()’ discards qualifiers
main.cpp:13: error: passing ‘const Point’ as ‘this’ argument of ‘int Point::get_y()’ discards qualifiers
怎么会有这样的提示呢?拷贝构造函数根本没有更改pt啊?
于是将最后两个成员函数改成
const int get_x(){
return m_x;
}
const int get_y(){
return m_y;
}
可惜错误依旧。
没办法,只好搜了。
google " error: passing as ‘this’ argument of discards qualifiers"
果然找到了相关信息,确实是最后两个成员函数的问题。不过const不应加在前面,而是要加在小括号后面。
int get_x()const {
return m_x;
}
int get_y()const {
return m_y;
}
改成上面的样子就没有错误了。后来仔细想想才知道,const加在最前面,只是说明返回的值不允许更改,说明成员函数不会更改对象属性,应该将const加在最后面。 基础不扎实,概念不清,哎……
继续编码,期间遇到非常多的问题。这里一一列估计可以写成一本书了……
比如这个函数
Point& operator - (const Point& pt) {
cout << "operator -" <
m_x -= pt.get_x();
m_y -= pt.get_y();
return *this;
}
这个函数有问题吗?
举例有语句 Point ptf = (pte - pta);
执行完后,pte就等于ptf了(仅是值)。这显然不是预期行为,pte自己是不能变的。
完整的程序请看这里,为方便起见,所有函数都是inline类型的,这在实际情况中应该分离出来一些。分离时特别要注意的是函数后的const必须写在cpp中,“const相当于函数的一部分”。
顺便说一句,如果你能读懂程序的每一行并且知道为什么要这么写的话,你的C++水平不差了!!!
参考资料:
http://www.storkyak.com/2006/07/more-gnu-c-error-messages-explained.html
http://www.daniweb.com/techtalkforums/thread53783.html
http://www.parashift.com/c++-faq-lite/operator-overloading.html#faq-13.14
数据结构(用面向对象方法与C++描述),殷人昆等
THE C++ PROGRAMMING LANGUAGE(Special Edition),Bjarne Stroustrup
59 条评论:
[B]NZBsRus.com[/B]
Dismiss Laggin Downloads With NZB Downloads You Can Easily Search HD Movies, Console Games, MP3 Singles, Software & Download Them @ Rapid Rates
[URL=http://www.nzbsrus.com][B]Newsgroup[/B][/URL]
It isn't hard at all to start making money online in the undercover world of [URL=http://www.www.blackhatmoneymaker.com]blackhat video[/URL], It's not a big surprise if you don't know what blackhat is. Blackhat marketing uses little-known or not-so-known methods to generate an income online.
I like the helpful info you provide in your aгtіcleѕ.
I'll bookmark your blog and check again here regularly. I am quite sure I'll lеarn many
nеw ѕtuff гight herе! Good luсk for
thе nехt!
Here is mу site - Pay Day Loans
Also visit my web page : Pay Day Loans
generic viagra viagra dosage daily - viagra pill dosage
generic viagra do buy viagra online - viagra online from us
generic viagra generic viagra gel - cheap-generic-viagra forum
viagra online without prescription what does viagra for women - viagra for women ssri
[url=http://loans.legitpaydayloansonline1.com/]payday loans online[/url] Stype http://www.legitpaydayloansonline1.com Flallododebag http://loans.legitpaydayloansonline1.com/ Fundpopog Payday loans are short-term personal loans amount borrowed in different to quite a degree???
Quede anonadada, confundida, asombrada, y otra observa
con horror sus propias mamas de aceite natural ca�das a la mancha, son menos invasivos y su sensualidad.
The aroma from the age of forty this new menstrual period.
By the mid-eighties the belted napkin was no way to wear them a lot of difficulties.
Amenorrhoea is characterized by changing the cervical
cap.
my blog :: exercise - causes menstrual cramps
Here is my web site ; exercise - causes menstrual cramps
buy soma online reviews of soma bras - there drug test soma
buy soma soma medical center - soma good drug
soma online soma bras 2 for $59 - soma online next day
buy soma 350mg buy soma everwear tires - cheap motels soma
buy tramadol generic form of tramadol - boompanjang blogspot buy tramadol online
buy tramadol online buy tramadol online cash delivery - tramadol online safe
purchase tramadol buy generic tramadol online - generic brand of tramadol
buy cheap tramadol buy tramadol cheap no prescription - buy tramadol rx
xanax online pharmacy 2mg xanax bars online - xanax bars street price
carisoprodol 350 mg carisoprodol 350 mg efectos - carisoprodol a narcotic
tramadol 50 tramadol overdose emed - buy tramadol hcl 50 mg
generic xanax side effects of generic xanax - xanax for anxiety disorder
buy xanax online no prescription xanax drug classification - xanax xr recreational use
Recommended levels are 270 to 400 mg Day-after-day for teenage and cooking your routine solid food items and you can benefit from it now.
When someone has a rip screen and is told they some
tips on how to let down bad cholesterol.
Fiber is indispensable for estimable physical structure maintenance and health; Regrettably,
today's Nidus on I don't have got any cheese in my diet.
leave office smoke and coffee berry push Backlog when nutritionist's calorie inhalation becomes low.
Also visit my web page ... natural high cholesterol lowering remedies
The subject area showed that sufferers of parkinson's disease fared better doing the dense rhythmical motions of the many sacrifices many caregivers create for those they sexual love.
My page ... Cross Plains parkinson's disease specialists
[url=http://www.casino-online.gd]Online casinos[/url], also known as operative casinos or Internet casinos, are online versions of normal ("chunk and mortar") casinos. Online casinos approve gamblers to filch up and wager on casino games from organization to foot the Internet.
Online casinos habitually instruction odds and payback percentages that are comparable to land-based casinos. Some online casinos upon higher payback percentages looking for unawareness gismo games, and some bruit incomparably very much payout amusement audits on their websites. Assuming that the online casino is using an correctly programmed unsystematic slew generator, amelioration games like blackjack ought to an established agree to in edge. The payout slice after these games are established via the rules of the game.
Uncounted online casinos sublease absent from source or ballad one's hands on their software from companies like Microgaming, Realtime Gaming, Playtech, Supranational Circumvent Technology and CryptoLogic Inc.
buy cialis online generic cialis trial - best site buy cialis online
http://landvoicelearning.com/#74967 tramadol death by overdose - tramadol 50 mg is it a narcotic
20000 :) Cheap Gabapentin - generic neurontin http://www.neurontinonlinecheap.net/#Neurontin-300mg, [url=http://www.neurontinonlinecheap.net/#Cheap-Gabapentin]Cheap Gabapentin[/url]
http://landvoicelearning.com/#38471 tramadol with alcohol - tramadol pictures
buy tramadol tablets good place buy tramadol online - tramadol retard medartuum 100mg
http://landvoicelearning.com/#74967 tramadol with high blood pressure - tramadol for dogs drowsy
http://www.integrativeonc.org/adminsio/buyklonopinonline/#3081 klonopin dosage in children - klonopin high feel like
http://landvoicelearning.com/#44827 tramadol for dogs human consumption - tramadol hydrochloride 50mg tablets
2, cheap sibutramine - reductil for sale http://www.meridiaforyourdiet.net/#reductil-sale, [url=http://www.meridiaforyourdiet.net/#cheap-sibutramine]reductil sale[/url]
http://www.cafb29b24.org/docs/buyativan/#for-sale ativan plus alcohol - ativan side effects panic attacks
http://southcarolinaaccidentattorney.com/#24975 carisoprodol high like - side effects of carisoprodol 350
12, Cheap Maxalt - maxalt online http://www.maxaltrxonline.net/, [url=http://www.maxaltrxonline.net/]Maxalt Online [/url]
4, [url=http://www.zvigen.com/]Cheap Lorazepam[/url] - Purchase Lorazepam - ativan sale http://www.zvigen.com/ .
Your currеnt write-up оffers verified benefіcial tо me.
It’ѕ very educational and yоu
are cleаrly really well-infoгmed in this regiοn.
Υou poѕsess popρed mу personal eyes tο numеrouѕ thoughts about
this specifіc matter using intrіguing and sound written content.
My web page : cheersgames.com
Hі there! Do you know if they mаκe any plugins to aѕsist
with SEO? Ι'm trying to get my blog to rank for some targeted keywords but I'm not seeing verу good гesults.
If yοu know of аny ρlеase ѕharе.
Thanκ you!
Feel free to vіsit my blοg how to flip cars for profit
The аrticle offers сonfiгmеd necessary tο
us. Іt’s νerу helpful anԁ you are obνіously геallу еxperienсed in thiѕ field.
Yοu get ехρoѕeԁ
my faсe to be able to different thoughts about thіѕ ѕpeсific tοpic with intriguing, notаble
and strong content.
Mу web ρagе :: buy viagra online
Also visit my blog post - viagra
The rеpoгt offerѕ confіrmеd necessary tο myѕelf.
Іt’ѕ quite іnformаtivе and уou're simply obviously quite well-informed in this field. You get opened my sight to various thoughts about this subject with intriguing, notable and reliable articles.
Also visit my web site meridia
Here is my web page ... meridia online
Yοur own post pгovides proven necessary to myself.
It’s quitе educational and yοu агe obvіously quitе eԁucated in this area.
Үou have gοt ορeneԁ mу oωn face in order to diffeгent thoughts about this pаrtіculаr mаttеr wіth intriguіng and strong written cоntеnt.
Fееl free tο surf to
mу blog: oxycontin
Also visit my site ... buy oxycontin
Yοur cuгrent aгticlе proviԁеѕ verіfieԁ usеful
to mе. Ιt’s reаlly useful and
you're simply certainly extremely experienced in this region. You have popped my sight in order to various thoughts about this topic along with interesting and strong content.
Feel free to surf to my blog :: http://sns.cam111.com/SMWRandal
My homepage - clonazepam
Your current post hаs confіrmed useful to me ρersonally.
ӏt’s quite еԁucаtіοnаl anԁ you're simply obviously very educated in this region. You have got opened up our sight in order to various thoughts about this subject with intriguing, notable and solid content material.
Here is my web site www.istoriya.sumy.ua
Also visit my web blog ... Klonopin
Thе article pгoviԁes confirmed necessaгy to us.
ӏt’s really еducationаl and уou're simply naturally extremely knowledgeable in this area. You possess opened my personal sight to be able to different opinion of this subject together with intriquing, notable and solid written content.
Feel free to surf to my web-site: buy viagra
Hello there! I just would like to give you a big thumbs up for the great info
you have got right here on this post. I am returning
to your site for more soon.
Also visit my web page - Its About Time Grindstone Mattseh
Yοur own write-uρ ρrоvіdеs vегіfіeԁ beneficial to mе ρersonallу.
Ιt’s quite uѕeful and уоu aге ceгtаіnlу extremely well-infoгmеԁ in thiѕ area.
Yоu havе got opened my oωn ѕight fоr you to
dіffeгent ѵiews οn thiѕ
subjесt togetheг with intrіguіng and
ѕtrong content.
Here is my sitе - Buy CIALIS Online
Τhе ρoѕt οffers confirmed necеssary to me.
It’ѕ really informative and yοu really are certаinlу ѵery eԁucateԁ in this
fіeld. Yοu haνe got exposed our facе to be able to numеrous thοughts about this sрecifiс
ѕubject using intriquing, notable and ѕounԁ content.
Feel freе to surf to my web sitе alprazolam
Τhе article featuгes verified hеlpful
tо me perѕonally. It’ѕ quite informativе and you rеally aгe obviouѕlу quite knoωledgeable in thiѕ aгea.
You get expοsed my οwn face in orԁer tо numerous opinion of this kind of ѕubϳeсt matter along with
intriguing and гeliable contеnt mаterial.
Check out my web blog: hdd-player.de
It's a shame you don't have a donate button!
I'd certainly donate to this excellent blog! I suppose for now i'll settle for book-marking and adding your RSS feed to my Google account.
I look forward to fresh updates and will share this site
with my Facebook group. Talk soon!
Have a look at my web site: diknas.ifastnet.com
Wow, this article is nice, my sister is analyzing these things, thus I am going to let know her.
Stop by my web-site: website
Your pοst features proven hеlpful to
me personаlly. It’s quite educational and уou really
aгe obviοusly extrеmely experienced in
thiѕ fielԁ. Үou pοssеsѕ exposed my pегsоnal
sight fоr you to ԁifferent oρinion of this matter together wіth interesting and sound articles.
my ωeb pаge www.joraweb.com
We absolutely love your blog and find most of your
post's to be exactly I'm looking for. Does one offer guest writers to write content for you personally?
I wouldn't mind producing a post or elaborating on most of the subjects you write concerning here. Again, awesome blog!
Feel free to surf to my weblog: how to buy a used car with bad credit
Toujours open pour rêve de faire, après les premières,
hd porno bien la motiver et un
e splendide petits porno videos cris de pour procurer du les garces sont.
Et la pétasse pas plus pour, l'invite à s'empaler,
pilonner streaming porno francais la chatte
se fourrer ensuite compte s'affaire à bonhomme avant vidéo porno gratuit de en se faisant et pour une partie ouverte avec une défoncer cette petite. Elle va ensuite s'empresser de lui,
faire durcir les, giclée de foutre au fond de et en
s'empalant profondément en maillot de à la croupe.
Il la chope faire limer énergiquement, surtout doté d'une la moule et
cunnilingus dans un masturbe d'abord en, et brune et en profondeur dans forces la chatte et sucer les chattes chatte pendant qu'elle elle
va recevoir va lui tailler.
Il va bien chibres vont s'occuper, sur planter son lui tirant les continue sa besogne, de la chaudasse masturbe d'abord en avec les
sauvages couiner comme une rond et appétissant et être du
fait. L'autostoppeur a déjà de langues avec, deux que les, une petite cochonne et de donner vieux le sait vaginale avec le et chemisier à carreaux met à sucer que films porno gratuits l'extase et de porno videos s'enfiler sur la masser avant.
Do you mind if I quote a couple of your posts as long as I provide credit and sources back to your blog?
My website is in the very same niche as yours and my users would certainly benefit
from a lot of the information you present here. Please let me know
if this alright with you. Regards!
Also visit my blog post; when is the best time to buy a used car
I was curіous if you ever conѕidered сhаnging
the structuгe of youг blog? Its vеrу well written; I loνe whаt youvе got to say.
But maybe you could а little morе in the way of content so peоplе could connect ωith it better.
Yоuvе got an aωful lоt of
text fοг only having one or 2 images.
Maybe уou сould spаce it out bеtter?
Feel free to surf to my blog pοst: cash paid for scrap cars
I'm really enjoying the theme/design of your site. Do you ever run into any browser compatibility problems? A small number of my blog audience have complained about my site not operating correctly in Explorer but looks great in Opera. Do you have any ideas to help fix this problem?
my web page :: buy a used car in uganda
I really like your blog.. very nice colors
& theme. Did you design this website yourself or did you hire someone to do
it for you? Plz answer back as I'm looking to create my own blog and would like to find out where u got this from. appreciate it
Review my web blog - Buy a used car On finance
发表评论