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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:52:58+00:00 2026-05-27T05:52:58+00:00

i got the .cpp and .h straight from the book, it seems as if

  • 0

i got the .cpp and .h straight from the book, it seems as if nothing is missing, but im getting these linking errors….

#ifndef SIMPLEVECTOR_H
#define SIMPLEVECTOR_H
#include <iostream>
#include <new>          // needed for bad__alloc exception
#include <cstdlib>      // needed for the exit function
using namespace std;

template <class T>
class simplevector
{
private:
    T *aptr;
    int arraysize;
    void memerror(); // handles mem aloc errors
    void suberror(); // handles subscripts out of range
public:
    simplevector() // default constructor
    { aptr = 0; arraysize = 0; }
    simplevector(int); // constructor
    simplevector(const simplevector &); // coppy constructor
    ~simplevector();
    int size()
        { return arraysize; }
    T &operator[](const int &); // overloaded [] operator
};

template <class T>
simplevector<T>::simplevector(int s)
{
    arraysize = s;
    // allocate memory for the array
    try
    {
        aptr = new T [s];
    }
    catch (bad_alloc)
    {
        memerror();
    }

    // initialize the array.
    for (int count = 0; count < arraysize; count++)
        *(aptr + count) = 0;
}

template <class T>
simplevector<T>::simplevector(const simplevector &obj)
{
    arraysize = obj.arraysize;
    aptr = new T [arraysize];
    if (aptr == 0)
        memerror();
    for(int count = 0; count < arraysize; count++)
        *(aptr + count) = *(obj.aptr + count);
}

template <class T>
simplevector<T>::~simplevector()
{
    if (arraysize > 0)
        delete [] aptr;
}

template <class T>
void simplevector<T>::memerror()
{
    cout << "ERROR: Cannot allocate memory.\n";
    exit(0);
}

template <class T>
T &simplevector<T>::operator [](const int &sub)
{
    if (sub < 0 || sub >= arraysize)
        suberror();
    return aptr[sub];
}

#endif

This program demonstrates the simplevector template:

#include <iostream>
#include "simplevector.h"
using namespace std;

int main()
{
    simplevector<int> inttable(10);
    simplevector<float> floattable(10);
    int x;

    //store values in the arrays.
    for (x = 0; x < 10; x++)
    {
        inttable[x] = (x * 2);
        floattable[x] = (x * 2.14);
    }

    //display the values in the arrays.
    cout << "these values are in inttable:\n";
    for (x = 0; x< 10; x++)
        cout << inttable[x] << " ";
    cout << endl;
    cout << "these values are in floattable:\n";
    for (x = 0; x< 10; x++)
        cout << floattable[x] << " ";
    cout << endl;

    //use the standard + operator on array elements.
    cout << "\nAdding 5 to each element of inttable"
        << " and floattable.\n";
    for (x = 0; x< 10; x++)
    {
        inttable[x] = inttable[x] + 5;
        floattable[x] = floattable[x] + 1.5;
    }

    //display the values in the array.
    cout << "These values are in inttable:\n";
    for (x = 0; x< 10; x++)
        cout << inttable[x] << " ";
    cout << endl;
    cout << "These values are in floattable:\n";
    for (x = 0; x< 10; x++)
        cout << floattable[x] << " ";
    cout << endl;
    // use the standard ++ operator on array elements.
    cout << "\nIncrementing each element of inttable and" 
        << " floattable.\n";
    for (x = 0; x< 10; x++)
    {
        inttable[x]++;
        floattable[x]++;
    }

    //display the values in the array.
    cout << "These values are in inttable:\n";
    for (x = 0; x< 10; x++)
        cout << inttable[x] << " ";
    cout << endl;
    cout << "These values are in floattable:\n";
    for (x = 0; x< 10; x++)
        cout << floattable[x] << " ";
    cout << endl;

    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-05-27T05:52:59+00:00Added an answer on May 27, 2026 at 5:52 am

    It’s right there in the errors you posted in the OP comments – you declared simplevector::suberror without ever defining it.

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

Sidebar

Related Questions

I've got this header (redone from a boost asio example): #ifndef MSGSRV_H_ #define MSGSRV_H_
I tried to build mongodb c++ 2.0 driver,but got the following error message: security_commands.cpp:(.text+0x865):
Got some code that is not mine and its producing this warning atm: iehtmlwin.cpp(264)
I've got a c++ app, with the following main.cpp: 1: #include <stdio.h> 2: #include
When I compiled the sample codes of C++, I got following info: c++ excxx_example_database_read.cpp
Possible Duplicate: Convert some code from C++ to C I've got some code that
i got a compile error which i do not understand. i have a h/cpp
I have got a f2.cpp file // f2.cpp #include <iostream> void f2() { std::cout
I've got an application that's using a static library I made. One .cpp file
I've got a program (LAMMPS, as it happens) spanning many .cpp/.h files, all of

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.