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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:43:39+00:00 2026-05-28T15:43:39+00:00

Im playing with my smart pointer class and I want to implement ++ and

  • 0

Im playing with my smart pointer class and I want to implement ++ and — operators with the following behavior: If pointer points to single variable or if it points to array and ++(–) moves pointer out of array bounds an exception should be thrown when trying to ++(–).

Something like that:

class A;

SmartPtr<A> s(new A[3]);
SmartPtr<A> s1(new A());
++s;//ok
--s;//ok
--s;//exception OutOfBounds thrown
++s1;//exception OutOfBounds thrown
--s1;//exception OutOfBounds thrown

I tried to use typeid. But it returns A type anyway.

A* arr=new A[3];
typeid(arr).name();//type is P1A
typeid(--arr).name();//type is P1A
typeid(arr+7).name();//type is P1A

So is there any way to determine does pointer point to “my” type of object after ++(–)?

  • 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-28T15:43:40+00:00Added an answer on May 28, 2026 at 3:43 pm

    new A[3] returns an A*, just like new A does. So you can’t distinguish them.

    If you want your class to do bounds checking, then you will need to explicitly tell it how many items are in the array.

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

Sidebar

Related Questions

I want to get ready for HTML 5 and start playing around with it.
I want to start playing around with Android. Downloaded the sources and followed the
I am just playing around to understand smart pointers and trying to make mine
Before I start playing the movie, I add a couple of cue points, then
When playing around with git , I sometimes try out things, then abort commands
I'm trying out the new LightSwitch beta 1 and getting the following error when
I've just start playing about with jQuery and want to place the results of
I just start playing with GWT I'm having a really hard time to make
I'm playing around at the start of a personal project in C# and MySQL.
Playing with log4net, I have seen the possibility to use a per-thread stack of

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.