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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:06:19+00:00 2026-06-18T14:06:19+00:00

Maybe someone can help me understand the error. I write this code: class Text

  • 0

Maybe someone can help me understand the error.

I write this code:

class Text
{
private:
    struct paragraph
    {
        vector<string> lines;       
    };

    vector<shared_ptr<paragraph>> paragraphs; 
public:

    Text()
    {
        paragraphs.push_back(shared_ptr<paragraph>(new paragraph()));
    }
};

int main()
{
    shared_ptr<Text> pText(nullptr);
    Text text();
    pText.reset(&text);
    return 0;
}

When I try to run it
I got this error:

    1>c:\program files\microsoft visual studio 10.0\vc\include\memory(1664): error C2541: 'delete' : cannot delete objects that are not pointers
1>          c:\program files\microsoft visual studio 10.0\vc\include\memory(1431) : see reference to function template instantiation 'void std::tr1::shared_ptr<_Ty>::_Resetp<_Ux>(_Ux (__cdecl *))' being compiled
1>          with
1>          [
1>              _Ty=Text,
1>              _Ux=Text (void)
1>          ]
1>          c:\program files\microsoft visual studio 10.0\vc\include\memory(1607) : see reference to function template instantiation 'std::tr1::shared_ptr<_Ty>::shared_ptr<_Ux>(_Ux (__cdecl *))' being compiled
1>          with
1>          [
1>              _Ty=Text,
1>              _Ux=Text (void)
1>          ]
1>          c:\documents and settings\owner\שולחן העבודה\e\class.cpp(29) : see reference to function template instantiation 'void std::tr1::shared_ptr<_Ty>::reset<Text(void)>(_Ux (__cdecl *))' being compiled
1>          with
1>          [
1>              _Ty=Text,
1>              _Ux=Text (void)
1>          ]

What is meant “cannot delete objects that are not pointers”?
I’m not trying to delete any object.

  • 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-18T14:06:21+00:00Added an answer on June 18, 2026 at 2:06 pm

    The line Text text(); does not do what you think it does.

    It parses it as the declaration of a function named text which accepts no argument and returns a value of type Text.

    This is the reason why your line pText.reset(&text); does not compile.

    However, you really do not want that line to compile: you are associating a shared_ptr object to a value with automatic storage duration: when the shared_ptr will go out of scope, it will try to delete that object, resulting in Undefined Behavior (most likely a crash in this case).

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

Sidebar

Related Questions

I am struggling really hard to understand this behavior so maybe someone can shed
This issue is driving me insane, so maybe someone could help me understand what
Can someone help me understand how to convert this sql query to a named_scope
Possible Duplicate: Can someone explain this template code that gives me the size of
Maybe someone can help me out. I have created a simple web user control,
I'm having trouble groking something in Linq - maybe someone can give me some
I'm a Linq noobie, maybe someone can point me in the right direction. What's
Can someone explain to me or maybe point a link or an example of
I find this question a little tricky. Maybe someone knows an approach to answer
Hi if someone could look at my code and maybe see something I am

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.