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
gr8b8m8_2l8
gr8b8m8_2l82y ago
Where's the friend keyword If you want that to be a friend
Revan
RevanOP2y ago
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
Revan
RevanOP2y ago
Σ
Σ2y ago
I thought you just call it like os << tk ?
Revan
RevanOP2y ago
do you mean my declaration parameters is wrong?
Σ
Σ2y ago
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
Revan
RevanOP2y ago
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
Revan
RevanOP2y ago
gr8b8m8_2l8
gr8b8m8_2l82y ago
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
Revan
RevanOP2y ago
yeah i can dm the code, thanks
emp0864
emp08642y ago
@revan4477 can you share you header file for TimedTask
Revan
RevanOP2y ago
gr8b8m8_2l8
gr8b8m8_2l82y ago
Issue was in the cpp file
Revan
RevanOP2y ago
thanks for all the help guys👍
Σ
Σ2y ago
It does work though
emp0864
emp08642y ago
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;
gr8b8m8_2l8
gr8b8m8_2l82y ago
Yeah in the friend operator you're defining how trying to cout an object will behave So you can cout << obj in the main
Σ
Σ2y ago
Isnt that the same as what hes doing?
gr8b8m8_2l8
gr8b8m8_2l82y ago
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
Σ
Σ2y ago
Gotcha
Want results from more Discord servers?
Add your server