我是一名初学者,正在编写一个帮助我节食的有趣程序。该程序尚未完成,但在我编写时正在编译。我不断收到标题中提到的错误:
Undefined symbols for architecture x86_64 with classes
我看过类似的问题,但它们都与模板和继承类有关,这与我的情况不同。我只是在宣布一个类(class),没什么特别的。我认为这与未正确定义类有关,但我无法弄清楚它是什么。这可能是我想念的愚蠢的东西,但我仍然被困住了。谢谢。
#include <iostream>
#include <string>
using namespace std;
class Meal
{
private:
string name;
int protein;
int carbs;
int fat;
int calories;
public:
Meal(string name, int calories, int protein, int carbs, int fat);
};
int main()
{
int calories = 0;
int rest_or_lift;
int create_or_not;
cout << "Enter 1 if it is a workout day, enter 2 if it is a rest day./n";
cin >> rest_or_lift;
if (rest_or_lift == 1)
{
calories = 2554;
}
else if (rest_or_lift == 2)
{
calories = 1703;
}
cout << "Enter 1 to input existing foods, enter 2 to create new foods./n";
cin >> create_or_not;
if (create_or_not == 1)
{
cout << "This aspect has not yet been created /n"; //need to fix this part
}
else if (create_or_not == 2)
{
do
{
string name;
int protein;
int carbs;
int fat;
int calories;
cout << "Enter the name of the food./n";
cin >> name;
cout << "Enter how many calories the food has. /n";
cin >> calories;
cout << "Enter how many grams of protein the food has /n";
cin >> protein;
cout << "Enter how many grams of carbs the food has /n";
cin >> carbs;
cout << "Enter how many grams of fats the food has /n";
cin >> fat;
Meal(name, calories, protein, carbs, fat);
cout << "Enter another food? Enter 1 to exit, 2 to continue.";
cin >> create_or_not;
} while (create_or_not == 2);
}
return 0;
}
最佳答案
Meal 类没有构造函数。你可以解决它,例如像这样:
class Meal
{
private:
string m_name;
int m_protein;
int m_carbs;
int m_fat;
int m_calories;
public:
Meal(string name, int calories, int protein, int carbs, int fat)
: m_name(name), m_protein(protein),
m_carbs(carbs), m_fat(fat), m_calories(calories)
{
}
};
关于c++ - 错误 : Undefined symbols for architecture x86_64 with classes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13509046/
大约一年前,我决定确保每个包含非唯一文本的Flash通知都将从模块中的方法中获取文本。我这样做的最初原因是为了避免一遍又一遍地输入相同的字符串。如果我想更改措辞,我可以在一个地方轻松完成,而且一遍又一遍地重复同一件事而出现拼写错误的可能性也会降低。我最终得到的是这样的:moduleMessagesdefformat_error_messages(errors)errors.map{|attribute,message|"Error:#{attribute.to_s.titleize}#{message}."}enddeferror_message_could_not_find(obje
我想为Heroku构建一个Rails3应用程序。他们使用Postgres作为他们的数据库,所以我通过MacPorts安装了postgres9.0。现在我需要一个postgresgem并且共识是出于性能原因你想要pggem。但是我对我得到的错误感到非常困惑当我尝试在rvm下通过geminstall安装pg时。我已经非常明确地指定了所有postgres目录的位置可以找到但仍然无法完成安装:$envARCHFLAGS='-archx86_64'geminstallpg--\--with-pg-config=/opt/local/var/db/postgresql90/defaultdb/po
我正在使用的第三方API的文档状态:"[O]urAPIonlyacceptspaddedBase64encodedstrings."什么是“填充的Base64编码字符串”以及如何在Ruby中生成它们。下面的代码是我第一次尝试创建转换为Base64的JSON格式数据。xa=Base64.encode64(a.to_json) 最佳答案 他们说的padding其实就是Base64本身的一部分。它是末尾的“=”和“==”。Base64将3个字节的数据包编码为4个编码字符。所以如果你的输入数据有长度n和n%3=1=>"=="末尾用于填充n%
我的瘦服务器配置了nginx,我的ROR应用程序正在它们上运行。在我发布代码更新时运行thinrestart会给我的应用程序带来一些停机时间。我试图弄清楚如何优雅地重启正在运行的Thin实例,但找不到好的解决方案。有没有人能做到这一点? 最佳答案 #Restartjustthethinserverdescribedbythatconfigsudothin-C/etc/thin/mysite.ymlrestartNginx将继续运行并代理请求。如果您将Nginx设置为使用多个上游服务器,例如server{listen80;server
我遵循MichaelHartl的“RubyonRails教程:学习Web开发”,并创建了检查用户名和电子邮件长度有效性的测试(名称最多50个字符,电子邮件最多255个字符)。test/helpers/application_helper_test.rb的内容是:require'test_helper'classApplicationHelperTest在运行bundleexecraketest时,所有测试都通过了,但我看到以下消息在最后被标记为错误:ERROR["test_full_title_helper",ApplicationHelperTest,1.820016791]test
我是rails的新手,想在form字段上应用验证。myviewsnew.html.erb.....模拟.rbclassSimulation{:in=>1..25,:message=>'Therowmustbebetween1and25'}end模拟Controller.rbclassSimulationsController我想检查模型类中row字段的整数范围,如果不在范围内则返回错误信息。我可以检查上面代码的范围,但无法返回错误消息提前致谢 最佳答案 关键是您使用的是模型表单,一种显示ActiveRecord模型实例属性的表单。c
我正在尝试编写一个将文件上传到AWS并公开该文件的Ruby脚本。我做了以下事情:s3=Aws::S3::Resource.new(credentials:Aws::Credentials.new(KEY,SECRET),region:'us-west-2')obj=s3.bucket('stg-db').object('key')obj.upload_file(filename)这似乎工作正常,除了该文件不是公开可用的,而且我无法获得它的公共(public)URL。但是当我登录到S3时,我可以正常查看我的文件。为了使其公开可用,我将最后一行更改为obj.upload_file(file
我克隆了一个rails仓库,我现在正尝试捆绑安装背景:OSXElCapitanruby2.2.3p173(2015-08-18修订版51636)[x86_64-darwin15]rails-v在您的Gemfile中列出的或native可用的任何gem源中找不到gem'pg(>=0)ruby'。运行bundleinstall以安装缺少的gem。bundleinstallFetchinggemmetadatafromhttps://rubygems.org/............Fetchingversionmetadatafromhttps://rubygems.org/...Fe
在Cooper的书BeginningRuby中,第166页有一个我无法重现的示例。classSongincludeComparableattr_accessor:lengthdef(other)@lengthother.lengthenddefinitialize(song_name,length)@song_name=song_name@length=lengthendenda=Song.new('Rockaroundtheclock',143)b=Song.new('BohemianRhapsody',544)c=Song.new('MinuteWaltz',60)a.betwee
我是Google云的新手,我正在尝试对其进行首次部署。我的第一个部署是RubyonRails项目。我基本上是在关注thisguideinthegoogleclouddocumentation.唯一的区别是我使用的是我自己的项目,而不是他们提供的“helloworld”项目。这是我的app.yaml文件runtime:customvm:trueentrypoint:bundleexecrackup-p8080-Eproductionconfig.ruresources:cpu:0.5memory_gb:1.3disk_size_gb:10当我转到我的项目目录并运行gcloudprevie