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

  • Home
  • SEARCH
  • 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 3480706
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T10:22:43+00:00 2026-05-18T10:22:43+00:00

Is it possible to handle a class with different instance variable types? Let’s say

  • 0

Is it possible to handle a class with different instance variable types? Let’s say I have a class that has two int instance variables, let’s call them:

@interface ClassA: NSObject {
  int x;
  int y;
}
@end

At the same time I want to extend it giving it the possibility to handle a different type on such instance variables like so:

@interface ClassB: ClassA {
  double x;
  double y;
}

Is this even possible?

  • 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-18T10:22:43+00:00Added an answer on May 18, 2026 at 10:22 am

    I’m pretty sure you can’t do that for two reasons:

    1. You can’t repeat instance variables (int x, double x).
    2. It’s pretty sketchy to inherit from one class, but then want to change the type of its instance variables.

    If you don’t want to make separate classes for these use-cases, perhaps an abstract superclass would work. If I more about what you’re trying to solve, I’d be able to be a bit more helpful in this area.

    What it seems like you really want is parametric polymorphism, which Objective-C does not support. Certain Cocoa classes, like the NSNumber family, use an abstract superclass with many concrete subclasses, presumably with different instance variable layouts (like you describe in your question). Then, logic is divided appropriately between the abstract and the specific. This is Cocoa’s Class Cluster design pattern, which is a sort of weakened, ad-hoc answer to the parametric polymorphism of languages like C++ and Haskell.

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

Sidebar

Related Questions

I have a ViewFlipper that presents 3 different views. Is it possible to have
I've put a little app together that has three tabs to show three different
I have a generic editor in ASP.NET page for editing lookup values for different
Possible Duplicate: Re-entrant locks in C# I've looked here on StackOverflow and on MSDN
I'm trying to create a simple class to read a csv file and store
Background I'm developing a django app for a vacation rental site. It will have
I'm writing a plugin-enabled android application here. I have 2 applications(2 apk), one is
I'm hoping to implement something like all of the great plugins out there for
I am developing a C++ application used to simulate a real world scenario. Based
we've got a problem with one of our non dpi aware MFC applications. If

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.