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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:03:16+00:00 2026-05-30T23:03:16+00:00

I am trying to use the stdlib stack in a class that I have

  • 0

I am trying to use the stdlib stack in a class that I have created, but I am having issues creating it dynamically.

Here is the relevant code from my header file “matcher.h”:

    private:

        stack<char> opens;

and here is the constructor that I am creating that only allocates the stack:

#include "matcher.h"
using namespace std;
//Creates a matcher object with the default values.
matcher::matcher()
{
    opens = new stack<char>;
}

The error I am getting is below:

matcher.cpp:19:17: error: no match for ‘operator=’ in ‘((matcher*)this)->matcher::opens = ((*(const std::deque<char, std::allocator<char> >*)(& std::deque<char, std::allocator<char> >())), (operator new(40u), (<statement>, ((std::stack<char>*)<anonymous>))))’

This says to me that the std::stack does not contain an assignment operator, which leads me to my question:

What method should I use in order to get a stack that will persist within my matcher object if it does not contain an assignment operator?

Thank you for your time.

  • 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-30T23:03:17+00:00Added an answer on May 30, 2026 at 11:03 pm

    opens is an object within the class, and so does not need to be allocated with new.

    If you want it to be default-constructed, then that will happen automatically – you don’t need to write any code to do that. If all the class members can be default constructed, then you don’t need to write a default-constructor for the class at all.

    If you have a member that can’t (or shouldn’t) be default constructed, then you do that in the constructor’s initialiser list, for example:

    class matcher {
    public:
        matcher() :
            number(42) // initialise with a value
        {}             // nothing else to do - "opens" is automatically initialised
    
    private:
        stack<char> opens;
        int number;
    };
    

    Only use new when you really need a dynamically allocated object, and make sure it gets deleted once you’ve finished with it – preferably using RAII, since it’s often hard to get it right any other way. If you want it to be tied to the lifetime of another object, then just place it inside that class as a member and don’t bother with dynamic allocation.

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

Sidebar

Related Questions

I have a code in which am trying to use outportb(), but while compiling
Trying to use an excpetion class which could provide location reference for XML parsing,
Trying to use a guid as a resource id in a rest url but
I have tried to use setjmp/longjmp in 64 bit Ubuntu, but it doesn't properly
I'm trying to use the CRT memory leak detection but I keep getting the
I'm trying to make my own shell in C, but am having trouble with
I'm trying use double type in openCL, but doesn't work anyway, i want use
I'm trying to use ldap_bind, but get an this error. error: âldap_bindâ was not
I have been trying to use Eclipse 3.6 as a Python editor. I install
I am trying use neo4j with Ruby on rails on Mac OSX. I have

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.