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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:42:40+00:00 2026-05-20T09:42:40+00:00

Ie. I want to code a class ADT that can be used like this:

  • 0

Ie. I want to code a class ADT that can be used like this:

myADT <type> objectA;

in the same way that someone would use a vector like:

vector <type> aVector;

I’m guessing maybe it has something to do with templates and overloading the <> operator, but how do I get it to take a data type as an argument?

  • 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-20T09:42:41+00:00Added an answer on May 20, 2026 at 9:42 am

    Let’s say you have a class that implements your ADT using a hard-coded typedef T:

    class ADT
    {
      public:
        typedef int T;
    
        ADT();
        T& operator[](size_t index);
        const T& operator[](size_t index) const;
        size_t size() const;
        ...
      private:
        T* p_;
        size_t size_;
    };
    

    (You have to work out the internal storage and member functions that are appropriate for your actual ADT).

    To change this so that you can specify T as done for std::vector etc.:

    template <typename T>    <-- specification of T moved to here
    class ADT
    {
      public:
                             <-- typedef for T removed from here
        ADT();
        T& operator[](size_t index);
        const T& operator[](size_t index) const;
        size_t size() const;
        ...
      private:
        T* p_;
        size_t size_;
    };
    

    Usage is then:

    ADT<int> an_adt_int;
    ADT<double> an_adt_double;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a code/class/script in JAVA that I want to be executed when someone
I often find I want to write code something like this in C#, but
I dont want to rename actual CODE (class), but how can I just rename
Using Eclipse I want to view the source code for a core Java class
In following code, I want to extend the behaviour of a class by deriving/subclassing
I'm overriding WndProc, so I want to write code like if (m.Msg == WM_COMMAND)
i have a table named item with four attribute name,code,class,value now i want to
I want to do, in Perl, the equivalent of the following Ruby code: class
I want to make chain-calling like jquery-way in c++. The sample: $('#obj').getParent().remove(); So, as
I want to use a temp directory that will be unique to this build.

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.