| Topic: |
DEVELOP > c-Plus-Plus |
| User: |
"fl" |
| Date: |
01 Jan 2008 09:29:31 PM |
| Object: |
Why can this not be initialized? |
Hi,
The following cannot be initilized. The error is LNK2001.
Bulk_item("345", 45, 3, .15);
bsk2 error LNK2001: symbole externe non r=A8=A6solu "public: virtual
double __thiscall Bulk_item::net_price(unsigned int)const " (?
net_price@Bulk_item@@UBENI@Z)
I don't know the reason. Could you tell me the problem? Thanks.
----------------------------
class Bulk_item : public Item_base {
public:
std::pair<size_t, double> discount_policy() const
{ return std::make_pair(min_qty, discount); }
// other members as before
Bulk_item* clone() const
{ return new Bulk_item(*this); }
Bulk_item(): min_qty(0), discount(0.0) { }
Bulk_item(const std::string& book, double sales_price,
std::size_t qty =3D 0, double disc_rate =3D 0.0):
Item_base(book, sales_price),
min_qty(qty), discount(disc_rate) { }
// redefines base version so as to implement bulk purchase
discount policy
double net_price(std::size_t) const;
private:
std::size_t min_qty; // minimum purchase for discount to apply
double discount; // fractional discount to apply
};
------------
.
|
|
| User: "Salt_Peter" |
|
| Title: Re: Why can this not be initialized? |
01 Jan 2008 10:44:31 PM |
|
|
On Jan 1, 10:29 pm, fl <rxjw...@gmail.com> wrote:
Hi,
The following cannot be initilized. The error is LNK2001.
Bulk_item("345", 45, 3, .15);
bsk2 error LNK2001: symbole externe non r=A8=A6solu "public: virtual
double __thiscall Bulk_item::net_price(unsigned int)const " (?
net_price@Bulk_item@@UBENI@Z)
I don't know the reason. Could you tell me the problem? Thanks.
----------------------------
class Bulk_item : public Item_base {
public:
std::pair<size_t, double> discount_policy() const
{ return std::make_pair(min_qty, discount); }
// other members as before
Bulk_item* clone() const
{ return new Bulk_item(*this); }
Bulk_item(): min_qty(0), discount(0.0) { }
Bulk_item(const std::string& book, double sales_price,
std::size_t qty =3D 0, double disc_rate =3D 0.0):
Item_base(book, sales_price),
min_qty(qty), discount(disc_rate) { }
// redefines base version so as to implement bulk purchase
discount policy
double net_price(std::size_t) const;
Where is the implementation of the above virtual member function?
The compiler says it can't resolve it.
The error given by compiler is quite clear.
private:
std::size_t min_qty; // minimum purchase for discount to apply
double discount; // fractional discount to apply};
------------
.
|
|
|
| User: "fl" |
|
| Title: Re: Why can this not be initialized? |
02 Jan 2008 06:54:25 AM |
|
|
On 1 jan, 23:44, Salt_Peter <pj_h...@yahoo.com> wrote:
On Jan 1, 10:29 pm, fl <rxjw...@gmail.com> wrote:
Hi,
The following cannot be initilized. The error is LNK2001.
Bulk_item("345", 45, 3, .15);
bsk2 error LNK2001: symbole externe non r=A8=A6solu "public: virtual
double __thiscall Bulk_item::net_price(unsigned int)const " (?
net_price@Bulk_item@@UBENI@Z)
I don't know the reason. Could you tell me the problem? Thanks.
----------------------------
class Bulk_item : public Item_base {
public:
=A0 =A0 std::pair<size_t, double> discount_policy() const
=A0 =A0 =A0 =A0 { return std::make_pair(min_qty, discount); }
=A0 =A0 // other members as before
=A0 =A0 Bulk_item* clone() const
=A0 =A0 =A0 =A0 { return new Bulk_item(*this); }
=A0 =A0 Bulk_item(): min_qty(0), discount(0.0) { }
=A0 =A0 Bulk_item(const std::string& book, double sales_price,
=A0 =A0 =A0 =A0 =A0 =A0 =A0 std::size_t qty =3D 0, double disc_rate =3D =
0.0):
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0Item_base(book, sales_price),
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0min_qty(qty), discount(disc_rate) { }=
=A0 =A0 // redefines base version so as to implement bulk purchase
discount policy
=A0 =A0 double net_price(std::size_t) const;
Where is the implementation of the above virtual member function?
The compiler says it can't resolve it.
The error given by compiler is quite clear.
private:
=A0 =A0 std::size_t min_qty; =A0 // minimum purchase for discount to app=
ly
=A0 =A0 double discount; =A0 =A0 =A0 // fractional discount to apply};
------------- Masquer le texte des messages pr=E9c=E9dents -
- Afficher le texte des messages pr=E9c=E9dents -- Masquer le texte des me=
ssages pr=E9c=E9dents -
- Afficher le texte des messages pr=E9c=E9dents -
Hi,
Yes, I have to define the routine. But for the following, I don't know
how to define it. Could you explain how to deal with ostream&? Give me
an example please. Thanks.
void display(std::ostream&) const;
.
|
|
|
| User: "=?UTF-8?B?RXJpayBXaWtzdHLDtm0=?=" |
|
| Title: Re: Why can this not be initialized? |
02 Jan 2008 07:22:14 AM |
|
|
On 2008-01-02 13:54, fl wrote:
On 1 jan, 23:44, Salt_Peter <pj_h...@yahoo.com> wrote:
On Jan 1, 10:29 pm, fl <rxjw...@gmail.com> wrote:
Hi,
The following cannot be initilized. The error is LNK2001.
Bulk_item("345", 45, 3, .15);
bsk2 error LNK2001: symbole externe non r¨¦solu "public: virtual
double __thiscall Bulk_item::net_price(unsigned int)const " (?
net_price@Bulk_item@@UBENI@Z)
I don't know the reason. Could you tell me the problem? Thanks.
----------------------------
class Bulk_item : public Item_base {
public:
std::pair<size_t, double> discount_policy() const
{ return std::make_pair(min_qty, discount); }
// other members as before
Bulk_item* clone() const
{ return new Bulk_item(*this); }
Bulk_item(): min_qty(0), discount(0.0) { }
Bulk_item(const std::string& book, double sales_price,
std::size_t qty = 0, double disc_rate = 0.0):
Item_base(book, sales_price),
min_qty(qty), discount(disc_rate) { }
// redefines base version so as to implement bulk purchase
discount policy
double net_price(std::size_t) const;
Where is the implementation of the above virtual member function?
The compiler says it can't resolve it.
The error given by compiler is quite clear.
private:
std::size_t min_qty; // minimum purchase for discount to apply
double discount; // fractional discount to apply};
------------- Masquer le texte des messages précédents -
- Afficher le texte des messages précédents -- Masquer le texte des messages précédents -
- Afficher le texte des messages précédents -
Hi,
Yes, I have to define the routine. But for the following, I don't know
how to define it. Could you explain how to deal with ostream&? Give me
an example please. Thanks.
void display(std::ostream&) const;
My guess is that the display() function should print out data about the
Bulk_item, so something like this might do:
void display(std::ostream& os) const
{
os << "Book:\t\t" << Item_base.getBook() << "\n";
os << "Price:\t\t" << Item_base.getPrice() << "\n";
os << "Min. Quantity:\t" << min_qty << "\n";
os << "Discount:\t" << discount << std::endl;
}
You can use os just like std::cout or an ofstream.
--
Erik Wikström
.
|
|
|
|
|
| User: "fl" |
|
| Title: Re: Why can this not be initialized? |
02 Jan 2008 06:45:10 AM |
|
|
On 1 jan, 23:44, Salt_Peter <pj_h...@yahoo.com> wrote:
On Jan 1, 10:29 pm, fl <rxjw...@gmail.com> wrote:
Hi,
The following cannot be initilized. The error is LNK2001.
Bulk_item("345", 45, 3, .15);
bsk2 error LNK2001: symbole externe non r=A8=A6solu "public: virtual
double __thiscall Bulk_item::net_price(unsigned int)const " (?
net_price@Bulk_item@@UBENI@Z)
I don't know the reason. Could you tell me the problem? Thanks.
----------------------------
class Bulk_item : public Item_base {
public:
=A0 =A0 std::pair<size_t, double> discount_policy() const
=A0 =A0 =A0 =A0 { return std::make_pair(min_qty, discount); }
=A0 =A0 // other members as before
=A0 =A0 Bulk_item* clone() const
=A0 =A0 =A0 =A0 { return new Bulk_item(*this); }
=A0 =A0 Bulk_item(): min_qty(0), discount(0.0) { }
=A0 =A0 Bulk_item(const std::string& book, double sales_price,
=A0 =A0 =A0 =A0 =A0 =A0 =A0 std::size_t qty =3D 0, double disc_rate =3D =
0.0):
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0Item_base(book, sales_price),
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0min_qty(qty), discount(disc_rate) { }=
=A0 =A0 // redefines base version so as to implement bulk purchase
discount policy
=A0 =A0 double net_price(std::size_t) const;
Where is the implementation of the above virtual member function?
The compiler says it can't resolve it.
The error given by compiler is quite clear.
private:
=A0 =A0 std::size_t min_qty; =A0 // minimum purchase for discount to app=
ly
=A0 =A0 double discount; =A0 =A0 =A0 // fractional discount to apply};
------------- Masquer le texte des messages pr=E9c=E9dents -
- Afficher le texte des messages pr=E9c=E9dents -- Masquer le texte des me=
ssages pr=E9c=E9dents -
- Afficher le texte des messages pr=E9c=E9dents -
OK now. One has to define the following function:
virtual double net_price(std::size_t) const
void display(std::ostream&) const
Thanks to all.
.
|
|
|
|
| User: "fl" |
|
| Title: Re: Why can this not be initialized? |
02 Jan 2008 06:16:28 AM |
|
|
On 1 jan, 23:44, Salt_Peter <pj_h...@yahoo.com> wrote:
On Jan 1, 10:29 pm, fl <rxjw...@gmail.com> wrote:
Hi,
The following cannot be initilized. The error is LNK2001.
Bulk_item("345", 45, 3, .15);
bsk2 error LNK2001: symbole externe non r=A8=A6solu "public: virtual
double __thiscall Bulk_item::net_price(unsigned int)const " (?
net_price@Bulk_item@@UBENI@Z)
I don't know the reason. Could you tell me the problem? Thanks.
----------------------------
class Bulk_item : public Item_base {
public:
=A0 =A0 std::pair<size_t, double> discount_policy() const
=A0 =A0 =A0 =A0 { return std::make_pair(min_qty, discount); }
=A0 =A0 // other members as before
=A0 =A0 Bulk_item* clone() const
=A0 =A0 =A0 =A0 { return new Bulk_item(*this); }
=A0 =A0 Bulk_item(): min_qty(0), discount(0.0) { }
=A0 =A0 Bulk_item(const std::string& book, double sales_price,
=A0 =A0 =A0 =A0 =A0 =A0 =A0 std::size_t qty =3D 0, double disc_rate =3D =
0.0):
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0Item_base(book, sales_price),
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0min_qty(qty), discount(disc_rate) { }=
=A0 =A0 // redefines base version so as to implement bulk purchase
discount policy
=A0 =A0 double net_price(std::size_t) const;
Where is the implementation of the above virtual member function?
The compiler says it can't resolve it.
The error given by compiler is quite clear.
private:
=A0 =A0 std::size_t min_qty; =A0 // minimum purchase for discount to app=
ly
=A0 =A0 double discount; =A0 =A0 =A0 // fractional discount to apply};
------------- Masquer le texte des messages pr=E9c=E9dents -
- Afficher le texte des messages pr=E9c=E9dents -- Masquer le texte des me=
ssages pr=E9c=E9dents -
- Afficher le texte des messages pr=E9c=E9dents -
They are examples for C++ primer 4th. director 15\Basket_main.cpp.
Don't know why they have problems.
http://www.informit.com/store/product.aspx?isbn=3D0201721481&redir=3D1
.
|
|
|
|
| User: "Rahul" |
|
| Title: Re: Why can this not be initialized? |
01 Jan 2008 11:16:58 PM |
|
|
On Jan 2, 9:44 am, Salt_Peter <pj_h...@yahoo.com> wrote:
On Jan 1, 10:29 pm, fl <rxjw...@gmail.com> wrote:
Hi,
The following cannot be initilized. The error is LNK2001.
Bulk_item("345", 45, 3, .15);
bsk2 error LNK2001: symbole externe non r=A8=A6solu "public: virtual
double __thiscall Bulk_item::net_price(unsigned int)const " (?
net_price@Bulk_item@@UBENI@Z)
I don't know the reason. Could you tell me the problem? Thanks.
----------------------------
class Bulk_item : public Item_base {
public:
std::pair<size_t, double> discount_policy() const
{ return std::make_pair(min_qty, discount); }
// other members as before
Bulk_item* clone() const
{ return new Bulk_item(*this); }
Bulk_item(): min_qty(0), discount(0.0) { }
Bulk_item(const std::string& book, double sales_price,
std::size_t qty =3D 0, double disc_rate =3D 0.0):
Item_base(book, sales_price),
min_qty(qty), discount(disc_rate) { }
// redefines base version so as to implement bulk purchase
discount policy
double net_price(std::size_t) const;
Where is the implementation of the above virtual member function?
The compiler says it can't resolve it.
The error given by compiler is quite clear.
private:
std::size_t min_qty; // minimum purchase for discount to apply
double discount; // fractional discount to apply};
------------
Isn't that reported by the linker?
.
|
|
|
| User: "Salt_Peter" |
|
| Title: Re: Why can this not be initialized? |
02 Jan 2008 12:21:28 AM |
|
|
On Jan 2, 12:16 am, Rahul <sam_...@yahoo.co.in> wrote:
On Jan 2, 9:44 am, Salt_Peter <pj_h...@yahoo.com> wrote:
On Jan 1, 10:29 pm, fl <rxjw...@gmail.com> wrote:
Hi,
The following cannot be initilized. The error is LNK2001.
Bulk_item("345", 45, 3, .15);
bsk2 error LNK2001: symbole externe non r=A8=A6solu "public: virtual
double __thiscall Bulk_item::net_price(unsigned int)const " (?
net_price@Bulk_item@@UBENI@Z)
I don't know the reason. Could you tell me the problem? Thanks.
----------------------------
class Bulk_item : public Item_base {
public:
std::pair<size_t, double> discount_policy() const
{ return std::make_pair(min_qty, discount); }
// other members as before
Bulk_item* clone() const
{ return new Bulk_item(*this); }
Bulk_item(): min_qty(0), discount(0.0) { }
Bulk_item(const std::string& book, double sales_price,
std::size_t qty =3D 0, double disc_rate =3D 0.0):
Item_base(book, sales_price),
min_qty(qty), discount(disc_rate) { }
// redefines base version so as to implement bulk purchase
discount policy
double net_price(std::size_t) const;
Where is the implementation of the above virtual member function?
The compiler says it can't resolve it.
The error given by compiler is quite clear.
private:
std::size_t min_qty; // minimum purchase for discount to apply
double discount; // fractional discount to apply};
------------
Isn't that reported by the linker?
yes it is
.
|
|
|
|
|
|
| User: "Abhishek Padmanabh" |
|
| Title: Re: Why can this not be initialized? |
01 Jan 2008 10:01:22 PM |
|
|
On Jan 2, 8:29=A0am, fl <rxjw...@gmail.com> wrote:
Hi,
The following cannot be initilized. The error is LNK2001.
Bulk_item("345", 45, 3, .15);
bsk2 error LNK2001: symbole externe non r=A8=A6solu "public: virtual
double __thiscall Bulk_item::net_price(unsigned int)const " (?
net_price@Bulk_item@@UBENI@Z)
I don't know the reason. Could you tell me the problem? Thanks.
----------------------------
class Bulk_item : public Item_base {
public:
=A0 =A0 std::pair<size_t, double> discount_policy() const
=A0 =A0 =A0 =A0 { return std::make_pair(min_qty, discount); }
=A0 =A0 // other members as before
=A0 =A0 Bulk_item* clone() const
=A0 =A0 =A0 =A0 { return new Bulk_item(*this); }
=A0 =A0 Bulk_item(): min_qty(0), discount(0.0) { }
=A0 =A0 Bulk_item(const std::string& book, double sales_price,
=A0 =A0 =A0 =A0 =A0 =A0 =A0 std::size_t qty =3D 0, double disc_rate =3D 0.=
0):
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0Item_base(book, sales_price),
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0min_qty(qty), discount(disc_rate) { }
=A0 =A0 // redefines base version so as to implement bulk purchase
discount policy
=A0 =A0 double net_price(std::size_t) const;
private:
=A0 =A0 std::size_t min_qty; =A0 // minimum purchase for discount to apply=
=A0 =A0 double discount; =A0 =A0 =A0 // fractional discount to apply};
You haven't shown enough code to understand what the reason could be
(the error message is also in a different language that I don't
understand) but the most probable reason would be a lacking definition
for member function net_price. The error message does not say anything
about the initialization being problematic.
.
|
|
|
|

|
Related Articles |
|
|