Program Error Visual Studio

Galq Dimitrova 1 Reputation point
2021-10-19T16:07:04.82+00:00

I have this error in visual studio, and i dont know what does mean
Link for picture for the error https://ibb.co/FswnRmj

[code]

include <ostream>

include <string>

include <istream>

class Stock {

int code;
std::string name;
double valuePerUnit;
int noUnits;

public:
Stock();

Stock(int c, std::string n, double v, int nu);

void setCode(int c);

void setName(std::string n);

void setValuePerUnit(double v);

void setNoUnits(int n);

int getCode();

std::string getName();

double getValuePerUnit();

double getNoUnits();

double calcAmount();

friend std::ostream & operator<<(std::ostream &out, const Stock &s);

friend std::istream &operator>>(std::istream &in, Stock& s);

};
[/code]

[/code]

include "Stock.h"

include <iostream>

Stock::Stock() {
code = 0;
name = "";
valuePerUnit = 1;
noUnits = 1;
}
Stock::Stock(int c, std::string n, double v, int nu)
{
code = c;
name = n;
valuePerUnit = v;
noUnits = nu;
}

void Stock::setCode(int c)
{
code = c;
}

void Stock::setName(std::string n)
{
name = n;
}

void Stock::setValuePerUnit(double v)
{
valuePerUnit = v;
}

void Stock::setNoUnits(int n)
{
noUnits = n;
}

int Stock::getCode()
{
return code;
}

std::string Stock::getName()
{
return name;
}

double Stock::getValuePerUnit()
{
return valuePerUnit;;
}

double Stock::getNoUnits()
{
return noUnits;;
}

double Stock::calcAmount()
{
return getNoUnits() * getValuePerUnit();
}

std::ostream& operator << (std::ostream &out, Stock &s)
{
out << "\nCode : " << s.getCode();
out << "\nName : " << s.getName();
out << "\nNumber Of Units : " << s.getNoUnits();
out << "\nCost of Unit : " << s.getValuePerUnit();
out << "\nTotal : " << s.calcAmount() << std::endl;

return out;

}

std::istream& operator >> (std::istream& in, Stock& s)
{
std::cout<<"Enter Stock Code ";
in>>s.code;

std::cout<<"Enter Stock Name ";
in>>s.name;

std::cout<<"Enter value per Unit : ";
in>>s.valuePerUnit;

std::cout<<"Enter Number of Units : ";
in>>s.noUnits;

return in;

}
[/code]

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,519 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Minxin Yu 9,866 Reputation points Microsoft Vendor
    2021-10-20T06:34:00.717+00:00

    Hi, @Galq Dimitrova
    Error:

    friend std::ostream & operator<<(std::ostream &out, const Stock &s);  
    
    std::ostream& operator << (std::ostream& out, Stock&  s)  
    {  
          out << "\nCode : " << s.getCode();  
          out << "\nName : " << s.getName();  
          out << "\nNumber Of Units : " << s.getNoUnits();  
          out << "\nCost of Unit : " << s.getValuePerUnit();  
          out << "\nTotal : " << s.calcAmount() << std::endl;  
          return out;  
    }  
    

    The declaration of the symbol isn't spelled the same as the definition of the symbol. Verify you use the correct spelling and capitalization in both the declaration and the definition, and wherever the symbol is used or called. You could refer to the document: Linker Tools Error LNK2019.

    Best regards,

    Minxin Yu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  2. RLWA32 40,021 Reputation points
    2021-10-20T15:38:40.687+00:00

    I cut and pasted the questioner's code into an newly created empty VS2019 project (version16.11.5) and it compiled and linked without error.