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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:28:24+00:00 2026-06-15T05:28:24+00:00

I’m using this class complex in a program to parse equations class complex {

  • 0

I’m using this class complex in a program to parse equations

class complex
{
    double real;
    double imag;
    stringstream complexStr;

public:
    complex(double re = 0, double im = 0)
    {
        real = re;
        imag = im;
        complexStr<<real<<"+j"<<imag;
    }

    complex(complex &t)
    {
        real = t.real;
        imag = t.imag;
    }

    void StrtoComplex(char *temp)
    {
        int i;

        for(i = 0; i < strlen(temp); i++)
            if(temp[i] == 'j' || temp[i] == 'i')
                break;

        real = atof(temp);//takes till the last valid char so after + or whitespace it ignores
        imag = atof(temp + i + 1);

        complexStr<<real<<"+j"<<imag;
    }

    friend complex operator+(complex &a, complex &b);
    friend complex operator-(complex &a, complex &b);
    friend complex operator-(complex &a);
    friend complex operator*(complex &a, complex &b);
    friend complex operator/(complex &a, complex &b);
    friend ostream &operator<<(ostream &s, complex &t);
    friend istream &operator>>(istream &s, complex &t);
};

//overloading + to add complex numbers
complex operator +(complex &a, complex &b)
{
    complex t;
    t.real = a.real + b.real;
    t.imag = a.imag + b.imag;
    return(t);
}
//overaloading - to subtract 2 complex no's
complex operator -(complex &a, complex &b)
{
    complex t;
    t.real = a.real - b.real;
    t.imag = a.imag - b.imag;
    return(t);
}

//overloading unary -
complex operator -(complex &a)
{
    complex t(-a.real, -a.imag);
    return(t);
}

//overloading * to multiply 2 complex no's
complex operator *(complex &a, complex &b)
{
    complex t;
    t.real = (a.real*b.real) - (a.imag*b.imag);
    t.imag = (a.real*b.imag) + (a.imag*b.real);
    return(t);
}
//overloading / to divide 2 complex no's
complex operator /(complex &a, complex &b)
{
    complex t;
    t.real = ((a.real*b.real) + (a.imag*b.imag))/(b.real*b.real + b.imag*b.imag);
    t.imag = ((a.real*b.imag) - (a.imag*b.real))/(b.real*b.real + b.imag*b.imag);
    return(t);
}

ostream &operator<<(ostream &s, complex &t)
{
    s<<t.complexStr.str();
    return s;
}

istream &operator>>(istream &s, complex &t)
{
    char *temp;

    s>>temp;
    t.StrtoComplex(temp);
    return s;
}

and I’m receiving this error:

 error C2248: 'std::basic_ios<_Elem,_Traits>::basic_ios' : cannot access private member declared in class 'std::basic_ios<_Elem,_Traits>'
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>
1>          ]
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\ios(176) : see declaration of 'std::basic_ios<_Elem,_Traits>::basic_ios'
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>
1>          ]
1>          This diagnostic occurred in the compiler generated function 'std::basic_stringstream<_Elem,_Traits,_Alloc>::basic_stringstream(const std::basic_stringstream<_Elem,_Traits,_Alloc> &)'
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>,
1>              _Alloc=std::allocator<char>
1>          ]

Please help I tried searching around but the answers seem to be specific to the program so posted this question.

  • 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-15T05:28:25+00:00Added an answer on June 15, 2026 at 5:28 am

    Your complex class has a std::stringstream member. When the compiler generates a copy constructor for complex, it will try to call the copy constructor for std::stringstream. But this fails because stringstream objects can’t be copied.

    I suggest you remove the stringstream member, and just write the needed fields to the output stream in your operator<< instead. If you want to make the string representation a member of the class, use an std::string member instead.

    If you really want to have a stringstream member (not recommended), you need to create your own copy constructor instead of the compiler-generated one.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I am using the SimpleRSS gem to parse a WordPress RSS feed. The only
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I am reading a book about Javascript and jQuery and using one of the
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text

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.