班级 |模块:总线问题
我是一名 C++ 初学者,正在使用类和模块。当我尝试运行该应用程序时,该应用程序给出以下错误:zsh:总线错误/Users/****/Documents/jacoProject/App
。在互联网上我搜索了很多,但我发现了一些我不理解的东西,并且无法应用于我的代码。
我应该实现析构函数吗?如果是这样,我该如何在我的班级中实现它?预先感谢
func.cxx
module;
#include <string>
export module airline_ticket;
export class AirlineTicket
{
public:
AirlineTicket();
double calculatePriceInDollars();
std::string getPassengerName();
void setPassengerName(std::string name);
int getNumberOfMiles();
void setNumberOfMiles(int miles);
bool hasEliteSuperRewardsStatus();
void setHasEliteSuperRewardsStatus(bool status);
private:
std::string q_passengerName;
int q_numberOfMiles;
bool q_hasEliteSuperRewardsStatus;
};
func_impl.cxx
module;
#include <string>
module airline_ticket;
AirlineTicket::AirlineTicket()
{
q_passengerName = "..not";
q_numberOfMiles = 0;
q_hasEliteSuperRewardsStatus = false;
}
double AirlineTicket::calculatePriceInDollars()
{
if (hasEliteSuperRewardsStatus())
{
return 0;
}
else
{
return getNumberOfMiles() * 0.1;
}
}
std::string AirlineTicket::getPassengerName()
{
return q_passengerName;
}
void AirlineTicket::setPassengerName(std::string name)
{
q_passengerName = name;
}
int AirlineTicket::getNumberOfMiles()
{
return q_numberOfMiles;
}
void AirlineTicket::setNumberOfMiles(int miles)
{
q_numberOfMiles = miles;
}
bool AirlineTicket::hasEliteSuperRewardsStatus()
{
return q_hasEliteSuperRewardsStatus;
}
void AirlineTicket::setHasEliteSuperRewardsStatus(bool status)
{
q_hasEliteSuperRewardsStatus = status;
}
main.cpp
#include <iostream>
import airline_ticket;
int main()
{
AirlineTicket myTicket;
myTicket.setPassengerName("Will SMith");
myTicket.setNumberOfMiles(450);
double ticketCost {myTicket.calculatePriceInDollars()};
std::cout << ticketCost << std::endl;
return 0;
}
I am a C ++ beginner and I am working with classes and modules. When I try to run the app, the app gives me the following error: zsh: bus error /Users/****/Documents/jacoProject/App
. On the internet I searched a lot, but I found things that I didn't understand and that I couldn't apply to my code.
Should I implement a destructor? If so how can I implement it with my class? Thanks in advance
func.cxx
module;
#include <string>
export module airline_ticket;
export class AirlineTicket
{
public:
AirlineTicket();
double calculatePriceInDollars();
std::string getPassengerName();
void setPassengerName(std::string name);
int getNumberOfMiles();
void setNumberOfMiles(int miles);
bool hasEliteSuperRewardsStatus();
void setHasEliteSuperRewardsStatus(bool status);
private:
std::string q_passengerName;
int q_numberOfMiles;
bool q_hasEliteSuperRewardsStatus;
};
func_impl.cxx
module;
#include <string>
module airline_ticket;
AirlineTicket::AirlineTicket()
{
q_passengerName = "..not";
q_numberOfMiles = 0;
q_hasEliteSuperRewardsStatus = false;
}
double AirlineTicket::calculatePriceInDollars()
{
if (hasEliteSuperRewardsStatus())
{
return 0;
}
else
{
return getNumberOfMiles() * 0.1;
}
}
std::string AirlineTicket::getPassengerName()
{
return q_passengerName;
}
void AirlineTicket::setPassengerName(std::string name)
{
q_passengerName = name;
}
int AirlineTicket::getNumberOfMiles()
{
return q_numberOfMiles;
}
void AirlineTicket::setNumberOfMiles(int miles)
{
q_numberOfMiles = miles;
}
bool AirlineTicket::hasEliteSuperRewardsStatus()
{
return q_hasEliteSuperRewardsStatus;
}
void AirlineTicket::setHasEliteSuperRewardsStatus(bool status)
{
q_hasEliteSuperRewardsStatus = status;
}
main.cpp
#include <iostream>
import airline_ticket;
int main()
{
AirlineTicket myTicket;
myTicket.setPassengerName("Will SMith");
myTicket.setNumberOfMiles(450);
double ticketCost {myTicket.calculatePriceInDollars()};
std::cout << ticketCost << std::endl;
return 0;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论