SlideShare a Scribd company logo
1 of 3
Download to read offline
Why won't my code run? I want to inherit everything from sailb.h class (base) into raceb.h class
(derived) and in main I want to set a raceb member variable equal to one of sailb member
variables but it does not work. language is c++
////////////////////////////////////Base Class////////////////////////////////////////
#ifndef sailb_h
#define sailb_h
#include
using namespace std;
class sailb {
public:
sailb();
double setWindSpeed(); //modifier
double getWindSpeed(); //accessor
private:
double windSpeed;
};
#endif
////////////////////////////////derived class/////////////////////////////////////////////////////////////////
#ifndef raceb_h
#define raceb_h
#include "sailb.h"
class raceb: public sailb {
public:
raceb();
void setDownWind();
double getDownWind();
p rivate:
double downWindSpeed;
};
#endif
///////////////main.cpp/////////////////////////////////////////////////////////////////////////////////////
#include
#include
#include "sailb.h"
#include "raceb.h"
using namespace std;
sailb::sailb() {windSpeed = 0;}
raceb::raceb() {}
void sailb::setWindSpeed() {
cout << "What is the speed of the wind in knots. ";
cin >> windSpeed;
}
double sailb::getWindSpeed() {
return windSpeed;
}
void raceb::setDownWind() {
downWindSpeed = getWindSpeed();
}
double raceb::getDownWind() {
return downWindSpeed;
}
int main() {
sailb s;
s.setWindSpeed();
raceb r;
r.setDownWind();
cout << r.getDownWind();
///////// Output = 0. So the windSpeed is being set to the default windspeed, but i want it to be set
to the speed that the user inputs.
Solution
You are creating two different objects. Both of the objects share different memory locations. To
make it work what you are trying to achieve just use one object of derived class. Main function
will look like:
int main() {
raceb r;
r.setWindSpeed();
r.setDownWind();
cout << r.getDownWind();
return 0;
}
-----------
One more error I saw is you have defined the prototype of "setWindSpeed();" as "double".
Make it void. For example:
class sailb {
public:
sailb();
void setWindSpeed(); / <------------------ it was double in your code
double getWindSpeed(); //accessor
private:
double windSpeed;
};

More Related Content

Similar to Why wont my code run I want to inherit everything from sailb.h cl.pdf

Rapid Prototyping FTW!!!
Rapid Prototyping FTW!!!Rapid Prototyping FTW!!!
Rapid Prototyping FTW!!!cloudbring
 
Nginx Workshop Aftermath
Nginx Workshop AftermathNginx Workshop Aftermath
Nginx Workshop AftermathDenis Zhdanov
 
Ratpack - Classy and Compact Groovy Web Apps
Ratpack - Classy and Compact Groovy Web AppsRatpack - Classy and Compact Groovy Web Apps
Ratpack - Classy and Compact Groovy Web AppsJames Williams
 
BADCamp 2008 Core Crazy
BADCamp 2008 Core CrazyBADCamp 2008 Core Crazy
BADCamp 2008 Core CrazyShaun Haber
 
Building web framework with Rack
Building web framework with RackBuilding web framework with Rack
Building web framework with Racksickill
 
Building scala with bazel
Building scala with bazelBuilding scala with bazel
Building scala with bazelNatan Silnitsky
 
Deploying Rails Applications with Capistrano
Deploying Rails Applications with CapistranoDeploying Rails Applications with Capistrano
Deploying Rails Applications with CapistranoAlmir Mendes
 
2016年のPerl (Long version)
2016年のPerl (Long version)2016年のPerl (Long version)
2016年のPerl (Long version)charsbar
 
Deploy Rails Application by Capistrano
Deploy Rails Application by CapistranoDeploy Rails Application by Capistrano
Deploy Rails Application by CapistranoTasawr Interactive
 
Using the Groovy Ecosystem for Rapid JVM Development
Using the Groovy Ecosystem for Rapid JVM DevelopmentUsing the Groovy Ecosystem for Rapid JVM Development
Using the Groovy Ecosystem for Rapid JVM DevelopmentSchalk Cronjé
 
Ruby on Rails survival guide of an aged Java developer
Ruby on Rails survival guide of an aged Java developerRuby on Rails survival guide of an aged Java developer
Ruby on Rails survival guide of an aged Java developergicappa
 
Angular JS in 2017
Angular JS in 2017Angular JS in 2017
Angular JS in 2017Ayush Sharma
 
Hacking with ruby2ruby
Hacking with ruby2rubyHacking with ruby2ruby
Hacking with ruby2rubyMarc Chung
 
Optaros Surf Code Camp Lab 1
Optaros Surf Code Camp Lab 1Optaros Surf Code Camp Lab 1
Optaros Surf Code Camp Lab 1Jeff Potts
 
Toolbox of a Ruby Team
Toolbox of a Ruby TeamToolbox of a Ruby Team
Toolbox of a Ruby TeamArto Artnik
 
Vagrant for real codemotion (moar tips! ;-))
Vagrant for real codemotion (moar tips! ;-))Vagrant for real codemotion (moar tips! ;-))
Vagrant for real codemotion (moar tips! ;-))Michele Orselli
 
NLIT 2011: Chef & Capistrano
NLIT 2011: Chef & CapistranoNLIT 2011: Chef & Capistrano
NLIT 2011: Chef & Capistranonickblah
 
DevOps in PHP environment
DevOps in PHP environment DevOps in PHP environment
DevOps in PHP environment Evaldo Felipe
 

Similar to Why wont my code run I want to inherit everything from sailb.h cl.pdf (20)

Rapid Prototyping FTW!!!
Rapid Prototyping FTW!!!Rapid Prototyping FTW!!!
Rapid Prototyping FTW!!!
 
Nginx Workshop Aftermath
Nginx Workshop AftermathNginx Workshop Aftermath
Nginx Workshop Aftermath
 
Docker Compose Explained
Docker Compose ExplainedDocker Compose Explained
Docker Compose Explained
 
Ratpack - Classy and Compact Groovy Web Apps
Ratpack - Classy and Compact Groovy Web AppsRatpack - Classy and Compact Groovy Web Apps
Ratpack - Classy and Compact Groovy Web Apps
 
BADCamp 2008 Core Crazy
BADCamp 2008 Core CrazyBADCamp 2008 Core Crazy
BADCamp 2008 Core Crazy
 
Building web framework with Rack
Building web framework with RackBuilding web framework with Rack
Building web framework with Rack
 
Building scala with bazel
Building scala with bazelBuilding scala with bazel
Building scala with bazel
 
Deploying Rails Applications with Capistrano
Deploying Rails Applications with CapistranoDeploying Rails Applications with Capistrano
Deploying Rails Applications with Capistrano
 
2016年のPerl (Long version)
2016年のPerl (Long version)2016年のPerl (Long version)
2016年のPerl (Long version)
 
Deploy Rails Application by Capistrano
Deploy Rails Application by CapistranoDeploy Rails Application by Capistrano
Deploy Rails Application by Capistrano
 
Using the Groovy Ecosystem for Rapid JVM Development
Using the Groovy Ecosystem for Rapid JVM DevelopmentUsing the Groovy Ecosystem for Rapid JVM Development
Using the Groovy Ecosystem for Rapid JVM Development
 
Ruby on Rails survival guide of an aged Java developer
Ruby on Rails survival guide of an aged Java developerRuby on Rails survival guide of an aged Java developer
Ruby on Rails survival guide of an aged Java developer
 
Angular JS in 2017
Angular JS in 2017Angular JS in 2017
Angular JS in 2017
 
Hacking with ruby2ruby
Hacking with ruby2rubyHacking with ruby2ruby
Hacking with ruby2ruby
 
Optaros Surf Code Camp Lab 1
Optaros Surf Code Camp Lab 1Optaros Surf Code Camp Lab 1
Optaros Surf Code Camp Lab 1
 
A Life of breakpoint
A Life of breakpointA Life of breakpoint
A Life of breakpoint
 
Toolbox of a Ruby Team
Toolbox of a Ruby TeamToolbox of a Ruby Team
Toolbox of a Ruby Team
 
Vagrant for real codemotion (moar tips! ;-))
Vagrant for real codemotion (moar tips! ;-))Vagrant for real codemotion (moar tips! ;-))
Vagrant for real codemotion (moar tips! ;-))
 
NLIT 2011: Chef & Capistrano
NLIT 2011: Chef & CapistranoNLIT 2011: Chef & Capistrano
NLIT 2011: Chef & Capistrano
 
DevOps in PHP environment
DevOps in PHP environment DevOps in PHP environment
DevOps in PHP environment
 

More from formaxekochi

help with 13. please Where are the photosynthetic pigments in Gre.pdf
help with 13. please Where are the photosynthetic pigments in Gre.pdfhelp with 13. please Where are the photosynthetic pigments in Gre.pdf
help with 13. please Where are the photosynthetic pigments in Gre.pdfformaxekochi
 
How important is UNIX® to the Internet Explain why and support your.pdf
How important is UNIX® to the Internet Explain why and support your.pdfHow important is UNIX® to the Internet Explain why and support your.pdf
How important is UNIX® to the Internet Explain why and support your.pdfformaxekochi
 
give an example of a strength and weakness of the accounting rate of.pdf
give an example of a strength and weakness of the accounting rate of.pdfgive an example of a strength and weakness of the accounting rate of.pdf
give an example of a strength and weakness of the accounting rate of.pdfformaxekochi
 
Find an example infectious disease for each of the term(s) or concept.pdf
Find an example infectious disease for each of the term(s) or concept.pdfFind an example infectious disease for each of the term(s) or concept.pdf
Find an example infectious disease for each of the term(s) or concept.pdfformaxekochi
 
Evaluate the following expression. Your answer must be in exact form.pdf
Evaluate the following expression. Your answer must be in exact form.pdfEvaluate the following expression. Your answer must be in exact form.pdf
Evaluate the following expression. Your answer must be in exact form.pdfformaxekochi
 
did enzyme denaturing affect the active site what amino acid residu.pdf
did enzyme denaturing affect the active site what amino acid residu.pdfdid enzyme denaturing affect the active site what amino acid residu.pdf
did enzyme denaturing affect the active site what amino acid residu.pdfformaxekochi
 
Describe andor draw the lymphatic system from capillariesto the mai.pdf
Describe andor draw the lymphatic system from capillariesto the mai.pdfDescribe andor draw the lymphatic system from capillariesto the mai.pdf
Describe andor draw the lymphatic system from capillariesto the mai.pdfformaxekochi
 
Consider the sulfur trioxide (SO3) molecule. What is the central atom.pdf
Consider the sulfur trioxide (SO3) molecule. What is the central atom.pdfConsider the sulfur trioxide (SO3) molecule. What is the central atom.pdf
Consider the sulfur trioxide (SO3) molecule. What is the central atom.pdfformaxekochi
 
What are this companys dividends per share for 2017Income State.pdf
What are this companys dividends per share for 2017Income State.pdfWhat are this companys dividends per share for 2017Income State.pdf
What are this companys dividends per share for 2017Income State.pdfformaxekochi
 
Which statement is trueA.The main goal of work teams is to share .pdf
Which statement is trueA.The main goal of work teams is to share .pdfWhich statement is trueA.The main goal of work teams is to share .pdf
Which statement is trueA.The main goal of work teams is to share .pdfformaxekochi
 
When developing a new software we should take into account how to cr.pdf
When developing a new software we should take into account how to cr.pdfWhen developing a new software we should take into account how to cr.pdf
When developing a new software we should take into account how to cr.pdfformaxekochi
 
What impact did Pythagoras have on EuclidSolutionPythagorasP.pdf
What impact did Pythagoras have on EuclidSolutionPythagorasP.pdfWhat impact did Pythagoras have on EuclidSolutionPythagorasP.pdf
What impact did Pythagoras have on EuclidSolutionPythagorasP.pdfformaxekochi
 
Tic Tac Toe game with GUI please dont copy and paste from google. .pdf
Tic Tac Toe game with GUI please dont copy and paste from google. .pdfTic Tac Toe game with GUI please dont copy and paste from google. .pdf
Tic Tac Toe game with GUI please dont copy and paste from google. .pdfformaxekochi
 
This is a U.S History questionThe 911 hijackers used fully-loade.pdf
This is a U.S History questionThe 911 hijackers used fully-loade.pdfThis is a U.S History questionThe 911 hijackers used fully-loade.pdf
This is a U.S History questionThe 911 hijackers used fully-loade.pdfformaxekochi
 
The PCAOB and SOX were created in 2002 and yet accounting frauds occ.pdf
The PCAOB and SOX were created in 2002 and yet accounting frauds occ.pdfThe PCAOB and SOX were created in 2002 and yet accounting frauds occ.pdf
The PCAOB and SOX were created in 2002 and yet accounting frauds occ.pdfformaxekochi
 
The main purpose of welfare is to provide incomes O A. for people who.pdf
The main purpose of welfare is to provide incomes O A. for people who.pdfThe main purpose of welfare is to provide incomes O A. for people who.pdf
The main purpose of welfare is to provide incomes O A. for people who.pdfformaxekochi
 
The following is the sample code for multithreading. Run it and expl.pdf
The following is the sample code for multithreading. Run it and expl.pdfThe following is the sample code for multithreading. Run it and expl.pdf
The following is the sample code for multithreading. Run it and expl.pdfformaxekochi
 
A quantity of HI was sealed in a tube, heated to 425C, and held at t.pdf
A quantity of HI was sealed in a tube, heated to 425C, and held at t.pdfA quantity of HI was sealed in a tube, heated to 425C, and held at t.pdf
A quantity of HI was sealed in a tube, heated to 425C, and held at t.pdfformaxekochi
 
a higher GDP means that the U.S. either produced more goods and serv.pdf
a higher GDP means that the U.S. either produced more goods and serv.pdfa higher GDP means that the U.S. either produced more goods and serv.pdf
a higher GDP means that the U.S. either produced more goods and serv.pdfformaxekochi
 
All EXCEPT which of the following are stages of mitosis a) S ph.pdf
All EXCEPT which of the following are stages of mitosis  a) S ph.pdfAll EXCEPT which of the following are stages of mitosis  a) S ph.pdf
All EXCEPT which of the following are stages of mitosis a) S ph.pdfformaxekochi
 

More from formaxekochi (20)

help with 13. please Where are the photosynthetic pigments in Gre.pdf
help with 13. please Where are the photosynthetic pigments in Gre.pdfhelp with 13. please Where are the photosynthetic pigments in Gre.pdf
help with 13. please Where are the photosynthetic pigments in Gre.pdf
 
How important is UNIX® to the Internet Explain why and support your.pdf
How important is UNIX® to the Internet Explain why and support your.pdfHow important is UNIX® to the Internet Explain why and support your.pdf
How important is UNIX® to the Internet Explain why and support your.pdf
 
give an example of a strength and weakness of the accounting rate of.pdf
give an example of a strength and weakness of the accounting rate of.pdfgive an example of a strength and weakness of the accounting rate of.pdf
give an example of a strength and weakness of the accounting rate of.pdf
 
Find an example infectious disease for each of the term(s) or concept.pdf
Find an example infectious disease for each of the term(s) or concept.pdfFind an example infectious disease for each of the term(s) or concept.pdf
Find an example infectious disease for each of the term(s) or concept.pdf
 
Evaluate the following expression. Your answer must be in exact form.pdf
Evaluate the following expression. Your answer must be in exact form.pdfEvaluate the following expression. Your answer must be in exact form.pdf
Evaluate the following expression. Your answer must be in exact form.pdf
 
did enzyme denaturing affect the active site what amino acid residu.pdf
did enzyme denaturing affect the active site what amino acid residu.pdfdid enzyme denaturing affect the active site what amino acid residu.pdf
did enzyme denaturing affect the active site what amino acid residu.pdf
 
Describe andor draw the lymphatic system from capillariesto the mai.pdf
Describe andor draw the lymphatic system from capillariesto the mai.pdfDescribe andor draw the lymphatic system from capillariesto the mai.pdf
Describe andor draw the lymphatic system from capillariesto the mai.pdf
 
Consider the sulfur trioxide (SO3) molecule. What is the central atom.pdf
Consider the sulfur trioxide (SO3) molecule. What is the central atom.pdfConsider the sulfur trioxide (SO3) molecule. What is the central atom.pdf
Consider the sulfur trioxide (SO3) molecule. What is the central atom.pdf
 
What are this companys dividends per share for 2017Income State.pdf
What are this companys dividends per share for 2017Income State.pdfWhat are this companys dividends per share for 2017Income State.pdf
What are this companys dividends per share for 2017Income State.pdf
 
Which statement is trueA.The main goal of work teams is to share .pdf
Which statement is trueA.The main goal of work teams is to share .pdfWhich statement is trueA.The main goal of work teams is to share .pdf
Which statement is trueA.The main goal of work teams is to share .pdf
 
When developing a new software we should take into account how to cr.pdf
When developing a new software we should take into account how to cr.pdfWhen developing a new software we should take into account how to cr.pdf
When developing a new software we should take into account how to cr.pdf
 
What impact did Pythagoras have on EuclidSolutionPythagorasP.pdf
What impact did Pythagoras have on EuclidSolutionPythagorasP.pdfWhat impact did Pythagoras have on EuclidSolutionPythagorasP.pdf
What impact did Pythagoras have on EuclidSolutionPythagorasP.pdf
 
Tic Tac Toe game with GUI please dont copy and paste from google. .pdf
Tic Tac Toe game with GUI please dont copy and paste from google. .pdfTic Tac Toe game with GUI please dont copy and paste from google. .pdf
Tic Tac Toe game with GUI please dont copy and paste from google. .pdf
 
This is a U.S History questionThe 911 hijackers used fully-loade.pdf
This is a U.S History questionThe 911 hijackers used fully-loade.pdfThis is a U.S History questionThe 911 hijackers used fully-loade.pdf
This is a U.S History questionThe 911 hijackers used fully-loade.pdf
 
The PCAOB and SOX were created in 2002 and yet accounting frauds occ.pdf
The PCAOB and SOX were created in 2002 and yet accounting frauds occ.pdfThe PCAOB and SOX were created in 2002 and yet accounting frauds occ.pdf
The PCAOB and SOX were created in 2002 and yet accounting frauds occ.pdf
 
The main purpose of welfare is to provide incomes O A. for people who.pdf
The main purpose of welfare is to provide incomes O A. for people who.pdfThe main purpose of welfare is to provide incomes O A. for people who.pdf
The main purpose of welfare is to provide incomes O A. for people who.pdf
 
The following is the sample code for multithreading. Run it and expl.pdf
The following is the sample code for multithreading. Run it and expl.pdfThe following is the sample code for multithreading. Run it and expl.pdf
The following is the sample code for multithreading. Run it and expl.pdf
 
A quantity of HI was sealed in a tube, heated to 425C, and held at t.pdf
A quantity of HI was sealed in a tube, heated to 425C, and held at t.pdfA quantity of HI was sealed in a tube, heated to 425C, and held at t.pdf
A quantity of HI was sealed in a tube, heated to 425C, and held at t.pdf
 
a higher GDP means that the U.S. either produced more goods and serv.pdf
a higher GDP means that the U.S. either produced more goods and serv.pdfa higher GDP means that the U.S. either produced more goods and serv.pdf
a higher GDP means that the U.S. either produced more goods and serv.pdf
 
All EXCEPT which of the following are stages of mitosis a) S ph.pdf
All EXCEPT which of the following are stages of mitosis  a) S ph.pdfAll EXCEPT which of the following are stages of mitosis  a) S ph.pdf
All EXCEPT which of the following are stages of mitosis a) S ph.pdf
 

Recently uploaded

How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxAnaBeatriceAblay2
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 

Recently uploaded (20)

How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 

Why wont my code run I want to inherit everything from sailb.h cl.pdf

  • 1. Why won't my code run? I want to inherit everything from sailb.h class (base) into raceb.h class (derived) and in main I want to set a raceb member variable equal to one of sailb member variables but it does not work. language is c++ ////////////////////////////////////Base Class//////////////////////////////////////// #ifndef sailb_h #define sailb_h #include using namespace std; class sailb { public: sailb(); double setWindSpeed(); //modifier double getWindSpeed(); //accessor private: double windSpeed; }; #endif ////////////////////////////////derived class///////////////////////////////////////////////////////////////// #ifndef raceb_h #define raceb_h #include "sailb.h" class raceb: public sailb { public: raceb(); void setDownWind(); double getDownWind(); p rivate: double downWindSpeed; }; #endif ///////////////main.cpp///////////////////////////////////////////////////////////////////////////////////// #include #include #include "sailb.h"
  • 2. #include "raceb.h" using namespace std; sailb::sailb() {windSpeed = 0;} raceb::raceb() {} void sailb::setWindSpeed() { cout << "What is the speed of the wind in knots. "; cin >> windSpeed; } double sailb::getWindSpeed() { return windSpeed; } void raceb::setDownWind() { downWindSpeed = getWindSpeed(); } double raceb::getDownWind() { return downWindSpeed; } int main() { sailb s; s.setWindSpeed(); raceb r; r.setDownWind(); cout << r.getDownWind(); ///////// Output = 0. So the windSpeed is being set to the default windspeed, but i want it to be set to the speed that the user inputs. Solution You are creating two different objects. Both of the objects share different memory locations. To make it work what you are trying to achieve just use one object of derived class. Main function will look like: int main() { raceb r; r.setWindSpeed();
  • 3. r.setDownWind(); cout << r.getDownWind(); return 0; } ----------- One more error I saw is you have defined the prototype of "setWindSpeed();" as "double". Make it void. For example: class sailb { public: sailb(); void setWindSpeed(); / <------------------ it was double in your code double getWindSpeed(); //accessor private: double windSpeed; };