向量作为构造函数中的参数 [英] Vectors as parameters in constructors

查看:73
本文介绍了向量作为构造函数中的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

我正在用矢量和课程练习。我有一个向量

在一个构造函数中定义,它只是无法用systax编译

错误投诉gcc:


代码在这里:

http ://www.nylxs.com/docs/workshops/recepe.h.html


test_cast.C:13:18:recepe:没有这样的文件或目录

在recepe.C中包含的文件:13:

recepe.h:112:错误:在'&''令牌之前语法错误

recepe.h:113:错误:`&''之前的语法错误

recepe.h:117:错误:语句错误')''令牌


我起初认为麻烦的是,我的班级类型并没有被接受作为向量的类型,但即使我将Ingr换成int,

此行仍然失败。


Ruben


-
http://www.mrbrk lyn.com - 有趣的东西
http://www.nylxs.com - 自由软件的领导力发展


如此多的移民团体席卷我们的城镇布鲁克林,就像亚特兰蒂斯一样,在世界的心灵中达到了神话般的比例--RI Safir 1998 <

http://fairuse.nylxs.com DRM是THEFT - 我们是利益攸关方 - RI Safir 2002


是的 - 我写自由软件......所以我就是这样


"我们面临的一个巨大问题是,我们正在成为我们自己的文化遗产的佃农 - 我们需要有能力参与我们自己的社会。


我是一名工程师。我选择了最适合工作的工具,政治被诅咒。<

你必须是一个愚蠢的工程师,因为自古埃及第一王朝以来,政治和技术一直在附着。我猜你错过了那个。


??数字千年的版权

Hello
I''m working out an exercise with vectors and classes. I have a vector
defined in a constructor which is just failing to compile with a systax
error complaint by gcc:

The code is here:

http://www.nylxs.com/docs/workshops/recepe.h.html

test_cast.C:13:18: recepe: No such file or directory
In file included from recepe.C:13:
recepe.h:112: error: syntax error before `&'' token
recepe.h:113: error: syntax error before `&'' token
recepe.h:117: error: syntax error before `)'' token

I thought at first that the trouble was that my class type wasn''t being
accepted as a type for the vector, but even when I swap out Ingr for int,
this line still fails.

Ruben

--
http://www.mrbrklyn.com - Interesting Stuff
http://www.nylxs.com - Leadership Development in Free Software

So many immigrant groups have swept through our town that Brooklyn, like Atlantis, reaches mythological proportions in the mind of the world - RI Safir 1998

http://fairuse.nylxs.com DRM is THEFT - We are the STAKEHOLDERS - RI Safir 2002

"Yeah - I write Free Software...so SUE ME"

"The tremendous problem we face is that we are becoming sharecroppers to our own cultural heritage -- we need the ability to participate in our own society."

"I''m an engineer. I choose the best tool for the job, politics be damned.<
You must be a stupid engineer then, because politcs and technology have been attached at the hip since the 1st dynasty in Ancient Egypt. I guess you missed that one."

?? Copyright for the Digital Millennium

推荐答案

Ruben写道:
Ruben wrote:

I我正在用矢量和类进行练习。我有一个向量

在一个构造函数中定义,它只是无法用systax编译

错误投诉gcc:


代码在这里:

http ://www.nylxs.com/docs/workshops/recepe.h.html



您不应将URL发布到上传到网络的C ++代码。相反,将一个

最小但可编译的示例放入新闻组消息的正文中。

You should not post URLs to C++ code uploaded to the web. Instead, put a
minimal, yet compilable example into the body of your newsgroup message.


test_cast.C:13:18:recepe :没有这样的文件或目录

在recepe.C中包含的文件中:13:

recepe.h:112:错误:'&''令牌之前的语法错误

recepe.h:113:错误:'&''之前的语法错误

recepe.h:117:错误:语法错误`)''token
test_cast.C:13:18: recepe: No such file or directory
In file included from recepe.C:13:
recepe.h:112: error: syntax error before `&'' token
recepe.h:113: error: syntax error before `&'' token
recepe.h:117: error: syntax error before `)'' token



文件recepe.h有问题。通过#include在第13行的
recepe.c中包含。

-

Christian Hackl

Something is wrong with the file "recepe.h" included via #include in
recepe.c in line 13.
--
Christian Hackl


Ruben写道:
Ruben wrote:

你好

我正在用矢量和类进行练习。我在构造函数中定义了一个向量

,它只是无法使用systax编译

错误投诉gcc:
Hello
I''m working out an exercise with vectors and classes. I have a vector
defined in a constructor which is just failing to compile with a systax
error complaint by gcc:



类vector和string在命名空间std。

The classes vector and string are in namespace std.


>

代码在这里:

http://www.nylxs.com/docs /workshops/recepe.h.html


test_cast.C:13:18:recepe:没有这样的文件或目录

包含在文件中来自recepe.C:13:

recepe.h:112:错误:&标记之前的语法错误

recepe.h:113:错误:语法错误在'&''标记之前

recepe.h:117:错误:语法错误之前`)''标记
>
The code is here:

http://www.nylxs.com/docs/workshops/recepe.h.html

test_cast.C:13:18: recepe: No such file or directory
In file included from recepe.C:13:
recepe.h:112: error: syntax error before `&'' token
recepe.h:113: error: syntax error before `&'' token
recepe.h:117: error: syntax error before `)'' token



编译器是寻找一个名为''recipe''的文件而不是找到它。它似乎
似乎没有定义Ingr类。在第117行,最后一个

参数缺少其类型。

The compiler is looking for a file called ''recipe'' and not finding it. It
also seems that the class Ingr is not defined. And in line 117, the last
parameter is missing its type.


2008年9月10日星期三18:42: 07 + 0200,Christian Hackl写道:
On Wed, 10 Sep 2008 18:42:07 +0200, Christian Hackl wrote:

Ruben写道:
Ruben wrote:

>我正在工作用向量和类进行练习。我在构造函数中定义了一个向量,它只是无法使用gcc编译系统错误:

代码在这里:
http://www.nylxs.com/docs/workshops /recepe.h.html



您不应将URL发布到上传到网络的C ++代码。相反,将一个

最小但可编译的示例放入新闻组消息的正文中。


You should not post URLs to C++ code uploaded to the web. Instead, put a
minimal, yet compilable example into the body of your newsgroup message.


> test_cast.C:13:18 :recepe:没有这样的文件或目录包含在文件中来自recepe.C:13:
recepe.h:112:错误:语句错误在'&''标记recepe.h:113:错误之前:'&''令牌recepe.h之前的语法错误:117:错误:
之前的语法错误`)''令牌
>test_cast.C:13:18: recepe: No such file or directory In file included
from recepe.C:13:
recepe.h:112: error: syntax error before `&'' token recepe.h:113: error:
syntax error before `&'' token recepe.h:117: error: syntax error before
`)'' token



文件recepe.h有问题。通过#include包含在第13行的
recepe.c中。


Something is wrong with the file "recepe.h" included via #include in
recepe.c in line 13.



#include< iostream>

#include< sstream>

#ifndef PHARM_H

#include" pharm.h"

#define PHARM_H

#endif

#ifndef EXCEPT_H

#define EXCEPT_H

#include< stdexcept>

#endif

#ifndef RECEPE_H

#define RECEPE_H

#endif

#ifdef VECTOR_H

#include< vector>

#define VECTOR_H

#endif


使用命名空间std;


class Ingr;

class解决方案;

class Admix;


class Ingr

{

public:

Ingr();

Ingr(const string picklist);

Ingr (string const c_name,double const c_concentration);

Ingr(string const c_name,double const c_concentration,string const c_mass_units,string const c_vol_units);

In gr(string const c_name,double const c_total_24_wgt,const string c_mass_units);

Ingr(Ingr&);


// getter方法


内联字符串名称()const {return _name;}

内联字符串选项列表()const {return _picklist;}

inline double concentration() const {return _concentration;}

内联字符串mass_units()const {return _mass_units;}

内联字符串vol_units()const {return _vol_units;}

inline double total_24_wgt()const {return _total_24_wgt;}

inline double wgt_kg_day()const {return _wgt_kg_day;}

inline double total_wgt_for_bag()const {return _total_wgt_for_bag; }


//推杆方法

内联字符串名称(字符串const m_name){return _name = m_name;}

inline string picklist(const string m_picklist){return _picklist = m_picklist;}

inline double concentration(const double m_concentration){return _concentration = m_concentration;}

内联字符串mass_units(const string m_mass){return _mass_units = m_mass;}

内联字符串vol_units(const string m_vol_units){return _vol_units = m_vol_units;}

inline double total_24_wgt(const double m_total_24_wgt){return _total_24_wgt = m_total_24_wgt;}

inline double total_wgt_for_bag(const double m_total_for_bag){return _total_wgt_for_bag = m_total_for_bag;}

inline double wgt_kg_day(const double m_wgt_kg_day){return _wgt_kg_day = m_wgt_kg_day;}

private:

string _name;

string _picklist;

double _concentration;

string _mass_units;

string _vol_units;

double _total_24_wgt;

double _total_wgt_for_bag;

double _wgt_kg_day;

};


class解决方案

{

public:

解决方案();

解决方案(const string m_name,int m_vol);

解决方案(const string m_picklist);

解决方案( const string m_name,const int m_vol,const string m_lyte,const double m_wgt,const string m_units);

// getter functions

inline string name()const {return _name ;}

内联字符串unit()const {return _unit;}

内联字符串lyte()const {return _lyte;}

内联字符串lyte_unit()const {return _lyte_units;}

inline string picklist()const {return _picklist;}

inline int vol()const {return _vol;}

inline double lyte_wgt()const {return _lyte_wgt;}

//推杆功能

内联字符串名称(const string m_name){return _name = m_name;}

内联字符串单元(const string m_unit){return _unit = m_unit;}

内联字符串lyte(const string m_lyte){return _lyte = m_lyte; } $ / $
内联字符串lyte_wgt(const string m_lyte_wgt){return _lyte_units = m_lyte_wgt;}

内联字符串选择列表(const string m_picklist){return _picklist = m_picklist;}

inline int vol(const int m _vol){return _vol = m_vol; }

inline double lyte_wgt(const double m_lyte_wgt){return _lyte_wgt = m_lyte_wgt;}

private:

string _name;

string _unit;

int _vol;

// kcl和mag prestocked solution需要lytes数据

string _lyte;

double _lyte_wgt;

string _lyte_units;

string _picklist;

};

class Admix

{

public:

vector< intctest;

Admix();

Admix(const Solution& c_bag);

Admix(const string& c_bag,const int& c_vol);

Admix(const string& c_bag,const int & c_vol,const vector< Ingr& c_drugs);

Admix(const Solution& c_bag,const vector< Ingr& c_drugs);

Admix(const Solution& c_bag,const Ingr& c_drug1);

Admix(const Solution& c_bag,const Ingr& c_drug1,const Ingr& c_drug2);

Admix(const Solution) & c_bag,const Ingr& c_drug1, const Ingr& c_drug2,const Ingr& c_drug3);

Admix(const Solution& c_bag,const Ingr& c_drug1,const Ingr& c_drug2,const Ingr& c_drug3,const Ingr& ; c_drug4);


// getters

inline int number_of_bags()const {return _number_of_bags;}

vector< Ingrdrugs( )const {return _drugs;}

inline Solution bag()const {return _bag; }


//推杆

inline int number_of_bags(int m_bags){return _number_of_bags = m_bags;}

inline vector< Ingrdrugs(vector< Ingrm_drugs){return _drugs = m_drugs; }

vector< Ingr>&药物(Ingr m_drug);

内联解决方案包(m_bag)const {return _bag = m_bag; }


//实用程序方法

double weight_calc(const string& mgkgperday,Solution& c_bag,const double& rate_ml_hr,const float& c_pt_wgt );


私人:

vector< Ingr_drugs;

解决方案_bag;

int _number_of_bags;

};


-
http://www.mrbrklyn.com - 有趣的东西
http://www.nylxs.com - 自由软件的领导力发展


这么多的移民团体席卷了我们的城镇布鲁克林和亚特兰蒂斯一样,在世界的心灵中达到了神话般的比例--RI Safir 1998

http://fairuse.nylxs.com DRM是盗窃者 - 我们是利益相关者 - RI Safir 2002


是的 - 我写自由软件......所以苏ME"


我们面临的巨大问题是,我们正在成为我们自己的文化遗产的佃农 - 我们需要有能力参与我们自己的社会。

我是工程师。我选择了最适合工作的工具,政治被诅咒。<

你必须是一个愚蠢的工程师,因为自古埃及第一王朝以来,政治和技术一直在附着。我猜你错过了那个。


??数字千年的版权


#include <iostream>
#include <sstream>
#ifndef PHARM_H
#include "pharm.h"
#define PHARM_H
#endif
#ifndef EXCEPT_H
#define EXCEPT_H
#include <stdexcept>
#endif
#ifndef RECEPE_H
#define RECEPE_H
#endif
#ifdef VECTOR_H
#include <vector>
#define VECTOR_H
#endif

using namespace std;

class Ingr;
class Solution;
class Admix;

class Ingr
{
public:
Ingr();
Ingr( const string picklist );
Ingr(string const c_name, double const c_concentration);
Ingr(string const c_name, double const c_concentration, string const c_mass_units, string const c_vol_units);
Ingr(string const c_name, double const c_total_24_wgt, const string c_mass_units);
Ingr(Ingr&);

//getter methods

inline string name() const { return _name;}
inline string picklist() const {return _picklist;}
inline double concentration() const{return _concentration;}
inline string mass_units() const{return _mass_units;}
inline string vol_units() const{return _vol_units;}
inline double total_24_wgt() const{return _total_24_wgt;}
inline double wgt_kg_day() const{return _wgt_kg_day;}
inline double total_wgt_for_bag() const{return _total_wgt_for_bag;}

//putter methods

inline string name(string const m_name){ return _name = m_name;}
inline string picklist(const string m_picklist){return _picklist = m_picklist;}
inline double concentration(const double m_concentration){return _concentration = m_concentration;}
inline string mass_units(const string m_mass){return _mass_units=m_mass;}
inline string vol_units(const string m_vol_units){return _vol_units=m_vol_units;}
inline double total_24_wgt(const double m_total_24_wgt){return _total_24_wgt=m_total_24_wgt;}
inline double total_wgt_for_bag(const double m_total_for_bag){return _total_wgt_for_bag=m_total_for_bag;}
inline double wgt_kg_day(const double m_wgt_kg_day){return _wgt_kg_day = m_wgt_kg_day;}

private:
string _name;
string _picklist;
double _concentration;
string _mass_units;
string _vol_units;
double _total_24_wgt;
double _total_wgt_for_bag;
double _wgt_kg_day;
};

class Solution
{
public:
Solution();
Solution(const string m_name, int m_vol);
Solution (const string m_picklist);
Solution (const string m_name, const int m_vol, const string m_lyte, const double m_wgt, const string m_units);
//getter functions
inline string name()const{return _name;}
inline string unit()const{return _unit;}
inline string lyte()const{return _lyte;}
inline string lyte_unit()const{return _lyte_units;}
inline string picklist()const{return _picklist;}
inline int vol()const{return _vol;}
inline double lyte_wgt()const{return _lyte_wgt;}

//putter functions
inline string name(const string m_name){return _name = m_name;}
inline string unit(const string m_unit){return _unit = m_unit;}
inline string lyte(const string m_lyte){return _lyte=m_lyte;}
inline string lyte_wgt(const string m_lyte_wgt){return _lyte_units = m_lyte_wgt;}
inline string picklist(const string m_picklist){return _picklist = m_picklist;}
inline int vol(const int m_vol){return _vol = m_vol; }
inline double lyte_wgt(const double m_lyte_wgt){return _lyte_wgt = m_lyte_wgt;}
private:
string _name;
string _unit;
int _vol;
//kcl and mag prestocked solution need lytes data
string _lyte;
double _lyte_wgt;
string _lyte_units;
string _picklist;
};
class Admix
{
public:
vector<intctest;
Admix();
Admix(const Solution &c_bag);
Admix(const string &c_bag, const int &c_vol);
Admix(const string &c_bag, const int &c_vol, const vector<Ingr&c_drugs);
Admix(const Solution &c_bag, const vector<Ingr&c_drugs);
Admix(const Solution &c_bag, const Ingr &c_drug1);
Admix(const Solution &c_bag, const Ingr &c_drug1, const Ingr &c_drug2);
Admix(const Solution &c_bag, const Ingr &c_drug1, const Ingr &c_drug2, const Ingr &c_drug3 );
Admix(const Solution &c_bag, const Ingr &c_drug1, const Ingr &c_drug2, const Ingr &c_drug3, const Ingr &c_drug4 );

//getters
inline int number_of_bags() const{ return _number_of_bags;}
vector<Ingrdrugs() const{ return _drugs;}
inline Solution bag() const{ return _bag; }

//putters
inline int number_of_bags(int m_bags){ return _number_of_bags = m_bags;}
inline vector <Ingrdrugs(vector<Ingrm_drugs){return _drugs = m_drugs; }
vector <Ingr>& drugs( Ingr m_drug);
inline Solution bag(m_bag) const{ return _bag = m_bag; }

//utility methods
double weight_calc(const string &mgkgperday, Solution &c_bag, const double &rate_ml_hr, const float &c_pt_wgt);


private:
vector <Ingr_drugs;
Solution _bag;
int _number_of_bags;
};


--
http://www.mrbrklyn.com - Interesting Stuff
http://www.nylxs.com - Leadership Development in Free Software

So many immigrant groups have swept through our town that Brooklyn, like Atlantis, reaches mythological proportions in the mind of the world - RI Safir 1998

http://fairuse.nylxs.com DRM is THEFT - We are the STAKEHOLDERS - RI Safir 2002

"Yeah - I write Free Software...so SUE ME"

"The tremendous problem we face is that we are becoming sharecroppers to our own cultural heritage -- we need the ability to participate in our own society."

"I''m an engineer. I choose the best tool for the job, politics be damned.<
You must be a stupid engineer then, because politcs and technology have been attached at the hip since the 1st dynasty in Ancient Egypt. I guess you missed that one."

?? Copyright for the Digital Millennium


这篇关于向量作为构造函数中的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆