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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:51:25+00:00 2026-06-16T02:51:25+00:00

I am testing an array template. It works fine for string type and int,

  • 0

I am testing an array template. It works fine for string type and int, but not for a typedef Student. I tried to figure out, but I can’t find the problem. I did not use a separate compilation as it is just a test. I am using Dev-C++. Your help will be very appreciated. The code is below:

#include <iostream>
#include <vector>

using namespace std;

template <typename T>
class Array
{
  public:
     Array(int initialSize);
     ~Array();
     T & operator[](int i);

  private:
      T * m_pData;
      int m_nSize;                
};

//Implementing member functions in the Array template
template <typename T>
Array <T>::Array(int initialSize)
{
   m_nSize = initialSize; 
   m_pData = new T [m_nSize];  
};

template <typename T>
T & Array <T>::operator[](int i)
{
   return  m_pData[i];
};

template <typename T>
Array <T>::~Array()
{
   delete[]  m_pData;
};


typedef struct Student{}students[0];

//test array class implementatition
int main()
{
  //creating an array of 20 integers, then assigning the value 50 at index 2

  Array <int> myArray (20);
  myArray[2] = 50;
  cout << myArray[2] <<endl;

  //creating an array of string of size 10, then assigning the string "Fred" at index 5
  //then display the string
  Array <string> nameArray (10);
  nameArray[5] = string("Fred");
  cout << nameArray[5] <<endl;


  //creating an array of Student of size 100, then assigning the value "123456789" at     index 4
  //then display the value at that index

  Array <Student> students (100);
  students[4] = Student("123456789");  //here is the problem!!!
  ///cout << students[4] <<endl;

  system ("pause");
   return 0;   
 }
  • 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-16T02:51:26+00:00Added an answer on June 16, 2026 at 2:51 am

    Student doesn’t have a constructor,you can’t call Student("123456789"); Try to define a constructor for Student:

    struct Student
    {
      Student(): age_(0), name_("") {}
      Student(int age): age_(age), name_("") {}
      Student(const std::string& name): name_(name){
      }
      int age_;
      std::string name_;
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have this array i tried usort and array_multisort but both didn't worked. I
Logically I am trying to figure out why my code is not working. foreach($list
I'm trying to process this array, first testing for the presence of a check,
In the code I'm testing, I have an NSPredicate and I'm filtering an array:
Here is some testing code: <script> var movieList = new Array(); var friendList= ;
Testing out someone elses code, I noticed a few JSP pages printing funky non-ASCII
i'm developing an array structure just for fun. This structure, generalized by a template
I got an Array like this: array('Testing'=>array( 'topic'=>$data['Testing']['topic'], 'content'=>$data['Testing']'content']) ); Now I have got
I have a pretty basic forum template I am working on for testing purposes
So I have the following method: template <class DT> //needs testing DT& LinkedSortedArrays<DT>::find (const

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.