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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:00:58+00:00 2026-05-31T19:00:58+00:00

I posted earlier today about template classes, but was pretty far off and got

  • 0

I posted earlier today about template classes, but was pretty far off and got a solution to my previous problem from here. Of course when that’s dealt with, there’s always a new one that I can’t seem to figure out.

Given the following constructor:

template <typename Type, int inSize>
sortedVector<Type, inSize>::sortedVector():
    size(inSize), vector(new Type[inSize]), amountElements(0)
{}

I want to make a dynamic array, which I then can insert elements of whatever type into via an add-method. The calls from main will look as follows:

sortedVector<Polygon, 10> polygons;
sortedVector<int, 6> ints;

How can I initialize the array to zero when it’s constructed? I can not set an object to zero 😉

I thought I was being smart and tried to overload the =-operator for Polygon and given an int it would do nothing. Turns out I can not do that ):

Any good suggestions?

Also, here’s the template class sortedVector:

template <typename Type, int inSize>
class sortedVector
{
public:
    sortedVector();
    int getSize();
    int getAmountElements()
    bool add(const Type &element);

private:
    Type *vector;
    int size;
    int amountElements;
};

and just in case also Polygon:

class Polygon
{
public:
    Polygon();
    Polygon(Vertex inVertArr[], int inAmountVertices);
    ~Polygon();
    void add(Vertex newVer);
    double area();
    int minx();
    int maxx();
    int miny();
    int maxy();
    int getAmountVertices() const;        
    friend bool operator > (const Polygon &operand1, const Polygon &operand2);
    friend bool operator < (const Polygon &operand1, const Polygon &operand2);

private:
    Vertex *Poly;
    int amountVertices;
};
  • 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-31T19:00:59+00:00Added an answer on May 31, 2026 at 7:00 pm

    Initialize the array elements to Type(). This is what the standard library containers do. For built-in numeric types, Type() is equivalent to 0. For class/struct types, Type() constructs a temporary default-constructed object.

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

Sidebar

Related Questions

Hi I posted this earlier and got some help but still no working solution.
Earlier I posted a problem about implementing wait and notify, but I wasn't very
This simple problem is kiling me. I posted something earlier about trying to clean
I posted earlier today about an error I was getting with using the predict
I posted another question earlier about getting the arguments from a context menu App.
earlier i posted a question about cin skipping input, and I got results to
I'm trying to find a solution to a question I posted earlier about synchronizing
I posted earlier with a problem regarding the same program but received no answers.
I posted a question earlier today when I'd not zeroed in quite so far
I posted earlier about how to do this, and got some great replies, and

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.