Why can this not be initialized?

F

fl

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;
private:
std::size_t min_qty; // minimum purchase for discount to apply
double discount; // fractional discount to apply
};
------------
 
A

Abhishek Padmanabh

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;
private:
    std::size_t min_qty;   // minimum purchase for discount to apply
    double discount;       // 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.
 
S

Salt_Peter

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.
 
R

Rahul

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.

Isn't that reported by the linker?
 
F

fl

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.





- Afficher le texte des messages précédents -- Masquer le texte des messages précédents -

- Afficher le texte des messages précédents -

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=0201721481&redir=1
 
F

fl

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.





- Afficher le texte des messages précédents -- Masquer le texte des messages précédents -

- Afficher le texte des messages précédents -

OK now. One has to define the following function:
virtual double net_price(std::size_t) const
void display(std::eek:stream&) const

Thanks to all.
 
F

fl

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.





- 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::eek:stream&) const;
 
E

Erik Wikström

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::eek:stream&) 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::eek:stream& 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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,967
Messages
2,570,148
Members
46,694
Latest member
LetaCadwal

Latest Threads

Top