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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:17:54+00:00 2026-05-23T10:17:54+00:00

I have this code main.cpp #include <iostream> #include functs.h using namespace std; int main()

  • 0

I have this code

main.cpp

#include <iostream>
#include "functs.h"

using namespace std;

int main()
{
    ArrayList *al = new ArrayList;
    return 0;
}

functs.h

using namespace std;
#ifndef FUNCTS_H_INCLUDED
#define FUNCTS_H_INCLUDED

class ArrayList;
#endif // FUNCTS_H_INCLUDED

functs.cpp

#include <iostream>
#include "functs.h"

class ArrayList{
    public:
        void add(int num);
        void add(int num, int index);
        void remove(int index);
        void removeNum(int num);
        string toString();
        ArrayList(int init);
    private:
        void resize();
        int size, cap;
        int *myList[10];
};

void ArrayList::add(int num){
    if (size>=cap/2)
    {
        resize();
    }
    *myList[size] = num;
    size++;
}

void ArrayList::resize(){
    int temp[cap*2];
    int i;
    for (i = 0; i < size; i++)
    {
        temp[i] = *myList[i];
    }
    *myList = temp;
}

ArrayList::ArrayList(){
    size = 0;
    cap = 10;
}

void ArrayList::add(int num, int index){
    int temp = *myList[index];
    int i;
    for (i = index; i < size; i++)
    {
        *myList[index] = num;
        num = temp;
        temp = *myList[i+1];
    }
    add(temp);
}

string ArrayList::toString(){
    string returnString = "{";
    int i;
    for (i = 0; i < size; i++)
        returnString.append(*myList[i] +",");
    returnString.replace(returnString.length()-1,1,"}");
    return returnString;
}

and I’m extremely new to C++ but whenever I try to compile the code it gives me a “size of ArrayList is not know”. Please help me figure out the error. =(

  • 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-23T10:17:54+00:00Added an answer on May 23, 2026 at 10:17 am

    Design/usage problems in your code notwithstanding, the most obvious problem is that you want to put the class definition in the functs.h file instead of the functs.cpp file:

    functs.h:

    // This is declaration is highly not recommended for use in header files.
    // using namespace std;
    
    #ifndef FUNCTS_H_INCLUDED
    #define FUNCTS_H_INCLUDED
    
    #include <string>
    
    class ArrayList{
        public:
            void add(int num);
            void add(int num, int index);
            void remove(int index);
            void removeNum(int num);
            std::string toString();
            ArrayList(int init);
        private:
            void resize();
            int size, cap;
            int *myList[10];
    };
    
    #endif // FUNCTS_H_INCLUDED
    

    functs.cpp:

    #include "functs.h"
    
    void ArrayList::add(int num){
        if (size>=cap/2)
        {
            resize();
        }
        *myList[size] = num;
        size++;
    }
    
    void ArrayList::resize(){
        int temp[cap*2];
        int i;
        for (i = 0; i < size; i++)
        {
            temp[i] = *myList[i];
        }
        *myList = temp;
    }
    
    ArrayList::ArrayList(){
        size = 0;
        cap = 10;
    }
    
    void ArrayList::add(int num, int index){
        int temp = *myList[index];
        int i;
        for (i = index; i < size; i++)
        {
            *myList[index] = num;
            num = temp;
            temp = *myList[i+1];
        }
        add(temp);
    }
    
    std::string ArrayList::toString(){
        std::string returnString = "{";
        int i;
        for (i = 0; i < size; i++)
            returnString.append(*myList[i] +",");
        returnString.replace(returnString.length()-1,1,"}");
        return returnString;
    }
    

    templatetypedef provides a reason why this is necessary. Basically the compiler needs to know how much space an ArrayList needs, and a class ArrayList; provides no such information.


    It’s not a good idea to declare using namespace std; inside a header file, because then everyone that includes the functs.h file (including your clients!) will also have a using namespace std;, increasing the possibility of name collisions.


    I highly recommend that you pick up a good introductory C++ book if you wish to learn C++ properly. You demonstrate in your question a rather big misunderstanding of how good C++ is written. That’s not to say you’re incompetent as a person, but there are some serious problems with the code you present. Just to name a few:

    • Standard C++ already provides a perfectly fine array class called std::vector. There’s no need to reinvent the wheel for what you’re doing. And even if you have to reinvent the wheel, an advanced understanding of C++ and plenty of C++ experience is a prerequisite to implementing an array container that’s appropriate for production use.
    • The public interface of your class is incomplete. There’s no way for clients to know how many elements are actually in the array.
    • int *myList[10]; declares a fixed array of 10 pointers to an int. This is not appropriate for an array class. Especially if you want the array to be resizable.
    • There’s not sufficient memory management for this class to be useful in any sense. There are no destructors and apparently the constructors are not complete (nor do they match), so you have no real logical place to put things like new[] and delete[].
    • You have a ArrayList *al = new ArrayList; but you don’t have a corresponding delete al; anywhere. This is a memory leak.
    • But the last point is moot because you should be using ArrayList a1; instead of ArrayList *al = new ArrayList;. The former will automatically “delete” itself at the end of the scope (in this case, the main() function) while the latter requires a delete statement. C++ is not like Java where unused new‘ed objects are automatically collected.

    I can’t comment on the correctness of the algorithms you used, because (and I’m sorry to say this because it’ll sound harsh) what you have simply won’t work. Again, I recommend that you pick up a good introductory C++ book, which will cover these kinds of issues. (I must emphasize that none of these shortcomings are a statement of you as a person. I’m talking specifically about the code you have in your question.)

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

Sidebar

Related Questions

I have this code #include <iostream> using namespace std; int main(int argc,char **argv) {
i have following code #include <iostream> #include <set> #include <string> using namespace std; template<class
i have following code #include <iostream> #include <string> using namespace std; string generate(){ for
I have the following source code in main.cpp: #include <iostream> #include <iomanip> int main()
I have this snippet of the code account.cpp #include account.h #include <iostream> #include <string>
I have this code :- using (System.Security.Cryptography.SHA256 sha2 = new System.Security.Cryptography.SHA256Managed()) { .. }
I have this code in jQuery, that I want to reimplement with the prototype
I have this code: chars = #some list try: indx = chars.index(chars) except ValueError:
I have this code that performs an ajax call and loads the results into
I have this code: CCalcArchive::CCalcArchive() : m_calcMap() { } m_calcMap is defined as this:

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.