I have some code on C++.
Bird.h
class Bird
{
std::string s;
static int i;
public:
Bird();
~Bird();
friend std::ostream& operator<<(std::ostream& os, Bird& b);
};
Bird.cpp
#include <iostream>
#include <sstream>
#include "Bird.h"
Bird::Bird()
{
++i;
std::stringstream ss;
ss<<"Bird#";
ss<<i;
s = ss.str();
}
Bird::~Bird()
{
i--;
}
std::ostream& operator<<(std::ostream& os, Bird& b)
{
const char* chr = (b.s).c_str();
return os << chr << std::endl;
}
Main.cpp
#include <iostream>
#include <sstream>
#include "Bird.h"
int Bird::i=0;
int main()
{
Bird b();
std::cout << b;
}
I am getting the following error:
Main.obj : error LNK2019: unresolved external symbol "class Bird __cdecl b(void)" (?b@@YA?AVBird@@XZ) referenced in function _main
But if I create Bird b;
it's OK.
What can I do?
You meant to write Bird b;
to create a Bird object.
Bird b()
is a function (called b
, taking no parameters and returning a Bird
), which you haven't implemented.