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 7691191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:33:58+00:00 2026-05-31T20:33:58+00:00

I have a problem when I call operator<< on a pointer. I have searched

  • 0

I have a problem when I call operator<< on a pointer. I have searched through SO and asked my question on Google, but all proposed solutions did not solve my problem. To illustrate my problem, please see a simplified piece of my code:

Marker.h:

class Marker {
     ...
public:
     friend std::ostream& operator<<(std::ostream& out, const Marker& marker);
     friend std::ostream& operator<<(std::ostream& out, Marker* marker);
};

inline std::ostream& operator<<(std::ostream& out, const Marker& marker) {
      out << "Marker " << marker._name << " of type " << marker._type << " at position " << marker._position;
      return out;
}

 inline std::ostream& operator<<(std::ostream& out, Marker* marker) {
      out << *marker;
      return out;
 }

Landmark.h:

 class Landmark {
       ...
       Marker* m_marker;
       ...
 };

Landmark.cpp:

 void Landmark::print( std::ostream& out )
 {
     out << "Marker GENERIC: " << m_marker << std::endl;
     //out << "Marker GENERIC: " << *m_marker << std::endl;
 }

This does not link under Visual Studio 2008. I get a load of unresolved external symbol errors. If i remove the friend std::ostream& operator<<(std::ostream& out, Marker* marker);, the code compiles, but instead of the expected formatted output, I get only the memory address of the pointer to the marker Marker* Landmark::m_marker. Uncommenting the second line turns my code into incompilable.

How should I overload operator<< so that I get the correct output?

I will be grateful for any help!

  • 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-05-31T20:33:59+00:00Added an answer on May 31, 2026 at 8:33 pm

    Here is a simple example:

    #include <iostream>
    
    namespace mine {
    class Marker {
    public:
         friend std::ostream& operator<<(std::ostream& out, const Marker& marker);
         friend std::ostream& operator<<(std::ostream& out, Marker* marker);
    };
    
    inline std::ostream& operator<<(std::ostream& out, const Marker& marker) {
         out << "Marker";
         return out;
    }
    
    inline std::ostream& operator<<(std::ostream& out, Marker* marker) {
         out << *marker;
         return out;
    }
    } // namespace mine
    
    int main() {
      mine::Marker marker;
      mine::Marker* m = &marker;
    
      std::cout << m << "\n";
    }
    

    And it works as expected.

    The error you point at is a linker error, it is telling you that the compiler emitted a call to a method for which no function was emitted.

    I will suppose that you have lied to us or that Visual Studio is once again wrong.

    • if you lied (ie, did not copy the exact code): note that when definining an inline method, the whole method body should be included before using it, therefore Landmark.cpp should include the methods definitions.
    • Alternatively, it may be necessary to help VS out by predeclaring the function before friending them so that VS understands that they do live in the mine namespace and not in the global namespace.

    Something like:

    namespace mine {
      class Marker;
    
      std::ostream& operator<<(std::ostream& out, const Marker& marker);
      std::ostream& operator<<(std::ostream& out, Marker* marker);
    
      class Marker {
      public:
        friend std::ostream& operator<<(std::ostream& out, const Marker& marker);
        friend std::ostream& operator<<(std::ostream& out, Marker* marker);
      };
    
      inline std::ostream& operator<<(std::ostream& out, const Marker& marker) {
        out << "Marker";
        return out;
      }
    
      inline std::ostream& operator<<(std::ostream& out, Marker* marker) {
        out << *marker;
        return out;
      }
    } // namespace mine
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Problem: I have a WCF service setup to be an endpoint for a call
Here's my problem: I have to call a web service with a secure header
I have a very weird problem: sometimes when I call nHibernate update to an
I have narrowed down my problem to the mysql_connect call I am doing in
The problem is the following. We have lots of ajax call via $.ajax function.
I have problem with return statment >.< I want to store all magazine names
I did not see anything that address my particular code problem. I have a
I have a differential operator that acts on two functions. To simplify the problem
I'm overloading operator new , but I recently hit a problem with alignment. Basically,
I'm facing an awkward problem using the subprocess.call operator in python for a script.

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.