 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
phal Guest
|
Posted: Thu Sep 29, 2005 8:11 pm Post subject: error string within class |
|
|
dear all
#include <iostream>
#include <string.h>
#include <vector>
using namespace std;
class Order
{
vector<string> ProductName;
vector<int> quantity;
vector<int> id;
public:
void SetOrder(int ID, string ProName, int qty);
void GetOrder(int ID, string Pro, int Qty);
void GetOrder(int ID);
};
void Order::SetOrder(int ID, string ProName, int qty)
{
ProductName.push_back(proName);
id.push_back(ID);
quantity.push_back(qty);
}
the ProductName.push_back(proName) create an error
I don't what the error with this code
anyone can help me? Thank
phal
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Victor Bazarov Guest
|
Posted: Sat Oct 01, 2005 1:33 am Post subject: Re: error string within class |
|
|
phal wrote:
| Quote: | [...]
void Order::SetOrder(int ID, string ProName, int qty)
^^^^^^^
{
ProductName.push_back(proName);
^^^^^^^ |
Notice any difference?
| Quote: | id.push_back(ID);
quantity.push_back(qty);
}
the ProductName.push_back(proName) create an error
I don't what the error with this code
anyone can help me? Thank
phal
|
V
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Wojtek Guest
|
Posted: Sat Oct 01, 2005 1:35 am Post subject: Re: error string within class |
|
|
U¿ytkownik "phal" <betterdie (AT) gmail (DOT) com> napisa³ w wiadomo¶ci
news:1127968218.840535.169410 (AT) g14g2000cwa (DOT) googlegroups.com...
| Quote: | dear all
#include <iostream
#include
#include
using namespace std;
class Order
{
vector
vector<int> quantity;
vector<int> id;
public:
void SetOrder(int ID, string ProName, int qty);
void GetOrder(int ID, string Pro, int Qty);
void GetOrder(int ID);
};
void Order::SetOrder(int ID, string ProName, int qty)
{
ProductName.push_back(proName);
id.push_back(ID);
quantity.push_back(qty);
}
the ProductName.push_back(proName) create an error
I don't what the error with this code
anyone can help me? Thank
phal
|
Hey!
Hmm, i haven't compiled your code, but I think that argument "ProName" in
function
void Order::SetOrder(int ID, string ProName, int qty)
and parameter proName in
ProductName.push_back(proName);
are not the same...
Am I right?
Wojtas
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
kanze Guest
|
Posted: Sat Oct 01, 2005 2:00 am Post subject: Re: error string within class |
|
|
phal wrote:
| Quote: | #include <iostream
|
Why? You don't use std::cout, std::cin or std::cerr.
I'm almost sure that this should be:
#include
<string.h> defines a set of functions for working with
char[]. <string> defines the class std::string.
| Quote: | #include <vector
using namespace std;
class Order
{
vector
vector<int> quantity;
vector<int> id;
public:
void SetOrder(int ID, string ProName, int qty);
void GetOrder(int ID, string Pro, int Qty);
void GetOrder(int ID);
};
|
Two comments:
-- wouldn't it make more sense to define a class OrderLine,
with a name, a quantity and an id, and have a single vector<
OrderLine >, than have three separate vectors, and
-- shouldn't the getter functions return something (and why a
getter function which requires all of the information you
are getting)?
| Quote: | void Order::SetOrder(int ID, string ProName, int qty)
{
ProductName.push_back(proName);
id.push_back(ID);
quantity.push_back(qty);
}
the ProductName.push_back(proName) create an error
|
What's the error? The only thing I can see is that string isn't
defined, and in that case, I would expect vector<string> to
fail. (Of course, it's always possible that <iostream> or
<vector> forward declare string, so you don't get an error until
you need the complete definition.)
--
James Kanze GABI Software mailto:james.kanze (AT) free (DOT) fr
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Yuri Khan Guest
|
Posted: Sat Oct 01, 2005 1:20 pm Post subject: Re: error string within class |
|
|
phal wrote:
| Quote: | dear all
#include <iostream
#include
|
You are including the wrong header. Standard strings are defined in
| Quote: | void Order::SetOrder(int ID, string ProName, int qty)
{
ProductName.push_back(proName);
id.push_back(ID);
quantity.push_back(qty);
}
the ProductName.push_back(proName) create an error
|
You might start by posting the error message here.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Ben Hutchings Guest
|
Posted: Sat Oct 01, 2005 1:34 pm Post subject: Re: error string within class |
|
|
hal <betterdie (AT) gmail (DOT) com> wrote:
| Quote: | dear all
#include <iostream
#include
|
<string> instead, otherwise there is no guarantee that the std::string
type will be defined.
| Quote: | #include <vector
using namespace std;
class Order
{
vector
vector<int> quantity;
vector<int> id;
public:
void SetOrder(int ID, string ProName, int qty);
void GetOrder(int ID, string Pro, int Qty);
void GetOrder(int ID);
};
void Order::SetOrder(int ID, string ProName, int qty)
{
ProductName.push_back(proName);
id.push_back(ID);
quantity.push_back(qty);
}
the ProductName.push_back(proName) create an error
I don't what the error with this code
|
In C++ (and most programming languages) names are case-sensitive, so
here you must type "ProName" and not "proName".
Ben.
--
Ben Hutchings
Having problems with C++ templates? Your questions may be answered by
<http://womble.decadentplace.org.uk/c++/template-faq.html>.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
BobR Guest
|
Posted: Sat Oct 01, 2005 1:37 pm Post subject: Re: error string within class |
|
|
phal wrote in message
<1127968218.840535.169410 (AT) g14g2000cwa (DOT) googlegroups.com>...
#include <iostream>
#include <string> // C++
#include <vector>
class Order {
std::vector<std::string> ProductName;
std::vector<int> quantity;
std::vector<int> id;
public:
void SetOrder(int const ID, std::string const ProName, int const
qty);
void GetOrder(int const ID, std::string &Pro, int &Qty);
void GetOrder(int ID);
};
void Order::SetOrder(int const ID, std::string const ProName, int const
qty){
// -- to point out your error: --
std::string proName( ProName );
ProductName.push_back( proName );
// -- or: --
// ProductName.push_back( ProName );
id.push_back( ID );
quantity.push_back( qty );
return;
}
| Quote: | the ProductName.push_back(proName) create an error
I don't what the error with this code
anyone can help me? Thank
phal
|
A simple typing error. C++ is 'case-sensitive'. A 'P' is not the same
as a
'p'.
Why not keep your data together and use only one vector? Suggestion:
class Order {
class Product{ public: // could be 'struct'
std::string PName;
int Quant;
int Ident;
};
std::vector<Product> vProducts;
public:
void SetOrder(int const ID, std::string const ProName, int const
qty);
void GetOrder(int const ID, std::string &Pro, int &Qty);
Product GetOrder(int const ID) const;
};
void Order::SetOrder(int const ID, std::string const ProName, int const
qty){
Product Prod;
Prod.PName = ProName;
Prod.Quant = qty;
Prod.Ident = ID;
vProducts.push_back(Prod);
return;
}
Always post the exact error you get.
--
Bob R
POVrookie
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Bo Persson Guest
|
Posted: Sat Oct 01, 2005 1:38 pm Post subject: Re: error string within class |
|
|
"phal" <betterdie (AT) gmail (DOT) com> skrev i meddelandet
news:1127968218.840535.169410 (AT) g14g2000cwa (DOT) googlegroups.com...
| Quote: | dear all
#include <iostream
#include
|
To use std::string, this should be
you get the C string functions, not the C++ string.
Bo Persson
| Quote: | #include <vector
using namespace std;
class Order
{
vector
vector<int> quantity;
vector<int> id;
public:
void SetOrder(int ID, string ProName, int qty);
void GetOrder(int ID, string Pro, int Qty);
void GetOrder(int ID);
};
void Order::SetOrder(int ID, string ProName, int qty)
{
ProductName.push_back(proName);
id.push_back(ID);
quantity.push_back(qty);
}
the ProductName.push_back(proName) create an error
I don't what the error with this code
anyone can help me? Thank
phal
|
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
hydrajak@yahoo.com Guest
|
Posted: Sat Oct 01, 2005 1:47 pm Post subject: Re: error string within class |
|
|
Well,
I'd hazard a guess that the symbol string is undefined. You should
include the C++ header file <string> not the C header file <string.h>
In the future it would be more helpful if you posted the compiler error
code also.
I would also mention that passing strings about "by value" as opposed
to "by reference" is probebly a bad idea. In the code you posted I
would be passing them about by const reference....
public:
void SetOrder( int ID, const string& ProName, int qty);
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Pete C Guest
|
Posted: Sat Oct 01, 2005 3:59 pm Post subject: Re: error string within class |
|
|
phal wrote:
| Quote: | void Order::SetOrder(int ID, string ProName, int qty)
{
ProductName.push_back(proName);
|
"ProName" and "proName" are not the same thing. Variable names are case
sensitive.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Alec Ross Guest
|
Posted: Sun Oct 02, 2005 1:34 am Post subject: Re: error string within class |
|
|
....
| Quote: |
void Order::SetOrder(int ID, string ProName, int qty)
{
------------------------------^ |
ProName
....
--
Alec Ross
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|