I started using C++ after learning Python, so I'm very very new to this. I'm writing a program and have 2 files in the project. I have my list.h class and my program. The list.h class, despite the fact that its a given class and should work, is ridled with errors. I won't post all the errors because its just too much but maybe if I show you guys the first error and help me fix it, I can keep working on the rest little by little so I can learn how to use this language from efficiently.

The code is:

// List.h
#ifndef _LIST_H_
#define _LIST_H_


#include <cstdlib>


class List {

public:
  List(size_t capacity=10); // constructor - allocates dynamic array
  List(const List &a); // copy constructor
  ~List(); // destructor

  int& operator[](size_t pos); // bracket operator
  List& operator=(const List &a); // assignment operator
  List& operator+=(const List &a); // += operator

  void append(int item);
  size_t size() const { return size_; }

private:
  void copy(const List &a);
  void resize(size_t new_size); // allocate new larger array
  int *data_; // dynamic array
  size_t size_; // size of dynamic array
  size_t capacity_; // capacity of dynamic array
};

inline int& List::operator[](size_t pos)
{
  return data_[pos];
}

#endif // _LIST_H_

The first error is, "Unresolved inclusion: <cstdlib>". What should I do?

Are you sure your compiling this with a C++ compiler? Could you be using a C compiler?

Yes. I was very careful in clicking new C++ project.

Did you check that the compiler was C++? It may be defaulting to C. I know NetBeans - C\C++ plugin will do this sometines.

I must've went over it a hundred times. The only thing I notice that might be the problem is my library. Maybe that's why I'm having problems with inclusion. The other errors are coming from the types so now I'm just trying to figure out how to get the program to include the library...to no avail though.

OK. What compiler and IDE are you using?

Are you sure that your IDE has <cstdlib> library?

I deleted eclipse and download it again, all seems to work as it should but for some reason the program is filled with errors that I'm not sure how to fix.

Can't help you if you don't post the code and the errors. My eyesight's too poor to see your monitor from where I'm sitting.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.