Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8880141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:06:35+00:00 2026-06-14T20:06:35+00:00

I have friend function in the class. (in header file. head.h) i have implemented

  • 0

I have friend function in the class. (in header file. head.h) i have implemented in head.cpp
and in head.h outside of the class i have ostream& operator<< (ostream& out, TreeNode* ptr);
i implemented in head.cpp as well. Is there any problem with that?

Header file

friend ostream& operator<< (ostream& out, const TreeDB& ptr);
 ostream& operator<< (ostream& out, TreeNode* ptr);

Implementation

ostream& operator<< (ostream& out, TreeNode* ptr)
{
 if(rhs!=NULL)
 {
  operator<<(out,ptr->Left());
  out<<(*(ptr->Entry()));
  operator<<(out,ptr->Right());
 }
 return out;
}




ostream& operator<< (ostream& out, const TreeDB& ptr)
{
 return (operator<<(out,ptr.root));
}

Error: undefined reference to ‘operator<<(std::basic_ostream >&,DBentry const&)’

DBentry is another class which manipulates the database entry

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T20:06:36+00:00Added an answer on June 14, 2026 at 8:06 pm

    When you got an undefined reference it is often an symptom of either a missing function definition, a small difference in signature from the definition and the declaration or that the definition of the function is not compiled/linked in.

    So check that your arguments match, that the namespaces match, and that the definition of the function indeed is compiled.

    As far as I can see in the code you have provided you have not defined an operator<< for DBEntry& const.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to call the function: friend ostream& operator<<(ostream& out, stack::myItem& theItem); that is
Say I have a class like so: class Ingredient { public: friend istream& operator>>(istream&
I have a GolfCourse class header gcourse.hh and I want to implement operator overload
Consider the following code: class MyClass { template <typename Datatype> friend MyClass& operator<<(MyClass& MyClassReference,
So, I have two classes: class Base { private: int number; public: friend ostream
I have this snippet of the code in my header : class A {
Is it possible to implement friend function and friend class (as in c++) in
Why it is not allowed to overload = using friend function? I have written
I have a class 'Vector3' which is compiled successfully. It contains both non-friend and
I have a problem with giving a template class a template friend in Sun

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.