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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:54:16+00:00 2026-06-11T12:54:16+00:00

xml_attribute.h #pragma once #ifndef XML_ATTRIBUTET_H #define XML_ATTRIBUTET_H #include <string> #include <iostream> struct XML_AttributeT{ std::string

  • 0

xml_attribute.h

#pragma once
#ifndef XML_ATTRIBUTET_H
#define XML_ATTRIBUTET_H

#include <string>
#include <iostream>

struct XML_AttributeT{

    std::string tag;
    std::string value;

    //constructors
    explicit XML_AttributeT(std::string const& tag, std::string const& value);
    explicit XML_AttributeT(void);

    //overloaded extraction operator
    friend std::ostream& operator << (std::ostream &out, XML_AttributeT const& attribute);
};
#endif

xml_attribute.cpp

#include "xml_attribute.h"

//Constructors
XML_AttributeT::XML_AttributeT(std::string const& tag_, std::string const& value_)
: tag{tag_}
, value{value_}
{}
XML_AttributeT::XML_AttributeT(void){}

//overloaded extraction operator
std::ostream& operator << (std::ostream &out, XML_AttributeT const attribute){
    return out << attribute.tag << "=" << attribute.value;
}

driver.cpp

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

int main(){
    using namespace std;

    XML_AttributeT a();
    cout << a << endl;

    return EXIT_SUCCESS;
}

The output from the driver is a ‘1’ but I want it to be an ‘=’ sign.
Why is it outputting the reference to a?
If I change XML_AttributeT a(); to XML_AttributeT a; it doesn’t even compile.

What did I do wrong?

  • 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-11T12:54:17+00:00Added an answer on June 11, 2026 at 12:54 pm

    chris is correct. Your initial issue is that XML_AttributeT a() is interpreted as a function declaration. clang++ will actually warn you of this:

    Untitled.cpp:33:21: warning: empty parentheses interpreted as a function declaration [-Wvexing-parse]
        XML_AttributeT a();
    

    You can use a{} instead to fix this.

    At this point you get a new error:

    Untitled.cpp:34:10: error: use of overloaded operator '<<' is ambiguous (with operand types 'ostream' (aka 'basic_ostream<char>') and 'XML_AttributeT')
        cout << a << endl;
    

    This is because of what jogojapan said. Your implemented operator<< is using XML_AttributeT const as the attribute type instead of XML_AttributeT const &. If you fix that, then it compiles and gives you the result you want.

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

Sidebar

Related Questions

I want to pass XML as a string in an XML attribute. <activity evt=&lt;FHS&gt;
I would like to convert some value from a XML attribute into valid HTML
How to use ImageDrawableLeft tag of XML attribute programmatically?
Is there an easy way to grab a attribute value from an xml item
I'm trying to iterate through a Twitter XML File, where the container tag is
I need to change the value of an XML attribute stored in a column
i want to get some value from xml file filtering with xml attribute. my
i want to get some value from xml file filtering with xml attribute. my
I have a set of XML as follows: ...<spotTerms> <terms xmlns= > <term tag=1m
I had a look at string escape into XML and found it very useful.

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.