Why is my program saying I didn't implement my friend insertion operator?
I'm getting a linker error, even though I'm pretty sure I implemented the friend operator correctly.
20 Replies
Where's the friend keyword
If you want that to be a friend
oh whoops i forgot to add that
ok i put the friend keyword in my header file and i moved the declaration into the class, but im still getting the same error
I thought you just call it like os << tk ?
do you mean my declaration parameters is wrong?
So in your class, you have friend ostream& operator<< etc.
Then define the ostream& operator<< externally
And to call it you would just say os << tk
oh im not personally calling the operator, the main program file thats given to me is, and when i try to compile it i get an error.
the message on vs code says theres not definition of the operator even though i did provide a defintion in my cpp file
You can't just say os<<tk
Not when you're defining what << will do
Unless you made a mistake with namespaces or something it looks fine?
If you zip your code and dm it I can take a closer look
yeah i can dm the code, thanks
@revan4477 can you share you header file for TimedTask
Issue was in the cpp file
thanks for all the help guys👍
It does work though
btw you don't need this methods to access the properties when you are using a friend method
int getRecords() const;
std::string getTaskName(int givenIndex) const;
std::string getUnitsofTime(int givenIndex) const;
std::chrono::steady_clock::duration getDuration(int givenIndex) const;
Yeah in the friend operator you're defining how trying to cout an object will behave
So you can cout << obj in the main
Isnt that the same as what hes doing?
No he is writing the operator << overload
Like how you did os << t.getText(), telling the program when you cout << obj, feed the obj.getText() function to os, then return os
Gotcha