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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:48:45+00:00 2026-06-17T13:48:45+00:00

I just learned about typedef. Suppose I have an instance: private: typedef std::string int

  • 0

I just learned about typedef. Suppose I have an instance:

private:
  typedef std::string int doubles abc;

when I make an accessors to instance abc:

returnType get(){...}

what should I put in the returnType? is it abc or the data type? thx

  • 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-17T13:48:46+00:00Added an answer on June 17, 2026 at 1:48 pm

    I’m not sure what you wanted to do here. Your typedef is invalid syntax, and “doubles” is no C++ type (but probably just a typo). Examples for valid syntax would be:

    typedef std::string abc;
    typedef int foo; 
    ...
    

    You can then use the typedef in function signatures, just like other types:

    abc getValue();
    

    Although you should put the typedef in the public part of your class if you want to use it in public member functions. And you should be aware that code outside of your class will always have to prefix the typedef with the name of your class, unless it is typedef‘d again.

    class SomeClass {
    public:
        typedef std::string foo;
    };
    
    // Somewhere outside SomeClass
    SomeClass::foo bar = ...
    typedef SomeClass::foo localFoo;
    localFoo fooBar = ...;
    

    Apart from that: typedef does not provide any way to have a variable represent more than one type. C++ is a statically typed language, so this is not directly possible. You can, however:

    • Use polymorphic classes with a common interface, instances of derived classes can then be treated like instances of the base class, but do different things
    • Use a union and some discriminator to store what type it is currently storing
    • Use void* and casting – Not recommended!
    • Use something like boost::variant, boost::any etc. like suggested by others

    Edit: Finally, on your use of the term “instance”: It is usally used to refer to an instance of a class, i.e. a particular object belonging to a class. What you mean is a “member variable”.

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

Sidebar

Related Questions

I've recently started learning C#. I just learned about properties and decided to make
I have just learned about the possibility to use OTHER_CODE_SIGN_FLAGS to specify the keychain
I've just learned about what std::function really is about and what it is used
I have just learned about recursion in Python and have completed assignments, one of
I have just learned about Android nine-patches idea, and it is a pretty good
I have just learned about Heroku and was pretty much excited to test it
Just learned about sigacation, also implemented another timer to make it more interesting. #include
I just learned about this fine looking syntax Collections.<String>emptyList() to get an empty List
I have just learned about XPath and I am wanting to read data from
I have just started learning about socket programming and learned about winsock and achieved

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.