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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:27:51+00:00 2026-06-11T13:27:51+00:00

I have a class with an overloaded insertion operator and it works in my

  • 0

I have a class with an overloaded insertion operator and it works in my driver:

#include <iostream>
#include <cstdlib>
#include "xml_attribute.h"

int main(){
    using namespace std;

    XML_AttributeT a("name","value");
    cout << a << endl;

    return EXIT_SUCCESS;
}

Outputs: name=”value”
works.

I want to leverage this capability in another class that includes this class:
header

#pragma once
#ifndef XML_ELEMENTT_H
#define XML_ELEMENTT_H

#include <string>
#include <vector>
#include <iostream>
#include "xml_attribute/xml_attribute.h"

struct XML_ElementT{

    std::string start_tag;
    std::vector<XML_AttributeT> attributes;
    bool single_tag;

    //Constructors
    explicit XML_ElementT(std::string const& start_tag, std::vector<XML_AttributeT> const& attributes, bool const& single_tag);
    explicit XML_ElementT(void);

    //overloaded extraction operator
    friend std::ostream& operator << (std::ostream &out, XML_ElementT const& element);

};
#endif

cpp

#include "xml_element.h"

//Constructors
XML_ElementT::XML_ElementT(std::string const& tag_, std::vector<XML_AttributeT> const& attributes_, bool const& single_tag_)
: start_tag{tag_}
, attributes{attributes_}
, single_tag{single_tag_}
{}
XML_ElementT::XML_ElementT(void){}

//overloaded extraction operator
std::ostream& operator << (std::ostream &out, XML_ElementT const& element){

    for (std::size_t i = 0; i < element.attributes.size()-1; ++i){
        out << element.attributes[i]; //<- Does not work
    }
    return out;// << element.attributes[element.attributes.size()-1];
}

Error:

undefined reference to `operator<<(std::basic_ostream<char, std::char_traits<char> >&, XML_AttributeT const&)

how can I get this to work?

  • 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-11T13:27:52+00:00Added an answer on June 11, 2026 at 1:27 pm

    undefined reference to `operator<<(std::basic_ostream<…>&, XML_AttributeT const&)

    That error means that the compiler has parsed the code appropriately and that you have a declaration for the operator with the signature above. But, the linker has not found the definition of that function in your program. This can be caused by different things, like failing to link the library or the .o where the operator is defined.

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

Sidebar

Related Questions

I have overloaded the + operator like this class sample { private : int
I have my class, where I overloaded the ! operator: class obj { public:
I have a class which does not have copy constructor or operator= overloaded. The
I have a class with an overloaded operator: IPAddress& IPAddress::operator=(IPAddress &other) { if (this
Why doesn't the STL string class have an overloaded char* operator built-in? Is there
I have a class that pretends to be an int, so it has overloaded
Say I have a class where I overloaded the operator == as such: Class
I'm having an issue. I have a class with an overloaded operator like this..
Suppose I have a class with overloaded operator new . class Class { public:
Hi assume that I have class A : using namespace std; template <class T>

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.