468,268 Members | 1,747 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,268 developers. It's quick & easy.

Vectors as parameters in constructors

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

Sep 10 '08 #1
10 1167
Ruben wrote:
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
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: 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
Something is wrong with the file "recepe.h" included via #include in
recepe.c in line 13.
--
Christian Hackl
Sep 10 '08 #2
Ruben wrote:
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 classes vector and string are in namespace std.
>
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
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.

Sep 10 '08 #3
On Wed, 10 Sep 2008 18:42:07 +0200, Christian Hackl wrote:
Ruben wrote:
>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

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: 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

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

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

Sep 10 '08 #4
On 2008-09-10 18:31, Ruben wrote:
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
In the future, please post the code (or relevant parts of it). Please
also see the FAQ, it contains a lot of good stuff.
http://www.parashift.com/c++-faq-lit...t.html#faq-5.8
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
Try std::vector<Ingr>
^^^^^

Also, you really need to read up on include-guards. What you have there
is some really weird stuff, but they are not good include-guards. All
you need is to put

#ifndef RECIPE_H
#define RECIPE_H

at the top and a

#endif

at the end of the file.

PS. It is spelt recipe, not recepe.

--
Erik Wikström
Sep 10 '08 #5
On Wed, 10 Sep 2008 18:55:28 +0200, Rolf Magnus wrote:
Ruben wrote:
>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 classes vector and string are in namespace std.

>The code is here:

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
Yeah, sorry. In tinkering with it I messed up the namespace, although I'm
calling in the namespace from other header files. I fixed the #include
and the namespace, but it's still giving me fustrating vector syntax
errors.

http://www.nylxs.com/docs/workshops/recepe.h.html
#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;
};


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.
I feel like I can't pull in the vector definition and I don't know why.

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

Sep 10 '08 #6
On Wed, 10 Sep 2008 17:10:59 +0000, Erik Wikström wrote:
On 2008-09-10 18:31, Ruben wrote:
>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

In the future, please post the code (or relevant parts of it). Please also
see the FAQ, it contains a lot of good stuff.
http://www.parashift.com/c++-faq-lit...t.html#faq-5.8
>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

Try std::vector<Ingr>
^^^^^

Also, you really need to read up on include-guards. What you have there is
some really weird stuff, but they are not good include-guards. All you
need is to put

#ifndef RECIPE_H
#define RECIPE_H

at the top and a

#endif

That's IT

I used

#ifdef VECTOR_H
#define VECTOR_H
#include <vector>
#endif

Its supposed to be

#ifndef VECTOR_H
#define VECTOR_H
#include <vector>
#endif

I want to conditionally include the header, so how can i do that without
multiple #endif statements?

at the end of the file.

PS. It is spelt recipe, not recepe.
--
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

Sep 10 '08 #7
On 10 Sep., 19:41, Ruben <ru...@www2.mrbrklyn.comwrote:
On Wed, 10 Sep 2008 17:10:59 +0000, Erik Wikstrm wrote:
[snip]
>
I used

#ifdef VECTOR_H
#define VECTOR_H
#include <vector>
#endif

Its supposed to be

#ifndef VECTOR_H
#define VECTOR_H
#include <vector>
#endif

I want to conditionally include the header, so how can i do that without
multiple #endif statements?
You should do as Erik recommended: put the include guard inside the
the header-file. There is normally no reason to avoid including the
same header more than once: the compiler should optimise this part
(assuming you were worried about long compilation times).

/Peter
Sep 10 '08 #8
On 2008-09-10 19:41, Ruben wrote:
On Wed, 10 Sep 2008 17:10:59 +0000, Erik Wikström wrote:
>On 2008-09-10 18:31, Ruben wrote:
>>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

In the future, please post the code (or relevant parts of it). Please also
see the FAQ, it contains a lot of good stuff.
http://www.parashift.com/c++-faq-lit...t.html#faq-5.8
>>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

Try std::vector<Ingr>
^^^^^

Also, you really need to read up on include-guards. What you have there is
some really weird stuff, but they are not good include-guards. All you
need is to put

#ifndef RECIPE_H
#define RECIPE_H

at the top and a

#endif


That's IT

I used

#ifdef VECTOR_H
#define VECTOR_H
#include <vector>
#endif

Its supposed to be

#ifndef VECTOR_H
#define VECTOR_H
#include <vector>
#endif

I want to conditionally include the header, so how can i do that without
multiple #endif statements?
You do *not* want to conditionally include vector, you *always* want to
include vector.

Change the following:

#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

into this:

#ifndef RECIPE_H
#define RECIPE_H

#include <iostream>
#include <sstream>
#include <stdexcept>
#include <vector>

#include "pharm.h"

and at the end of the file put this:

#endif

And then adjust whatever other header-files you have to follow the same
pattern.

--
Erik Wikström
Sep 10 '08 #9
On Wed, 10 Sep 2008 11:04:19 -0700, peter koch wrote:
On 10 Sep., 19:41, Ruben <ru...@www2.mrbrklyn.comwrote:
>On Wed, 10 Sep 2008 17:10:59 +0000, Erik Wikström wrote:
[snip]
>>
I used

#ifdef VECTOR_H
#define VECTOR_H
#include <vector>
#endif

Its supposed to be

#ifndef VECTOR_H
#define VECTOR_H
#include <vector>
#endif

I want to conditionally include the header, so how can i do that without
multiple #endif statements?
You should do as Erik recommended: put the include guard inside the the
header-file. There is normally no reason to avoid including the same
header more than once: the compiler should optimise this part (assuming
you were worried about long compilation times).

/Peter

Please define an include guard? Thanks. I've always been weak on this.

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

Sep 11 '08 #10
Ruben <ru***@www2.mrbrklyn.comkirjutas:
>
Please define an include guard? Thanks. I've always been weak on
this.
http://en.wikipedia.org/wiki/Include_guard
Sep 11 '08 #11

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

12 posts views Thread by Dave Theese | last post: by
16 posts views Thread by Emanuel Ziegler | last post: by
19 posts views Thread by Daniel Billingsley | last post: by
17 posts views Thread by Ben R. | last post: by
5 posts views Thread by roberts.noah | last post: by
reply views Thread by kermitthefrogpy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.