Header
template <class T> class arraylist {
private:
T * data; // Pointer to the dynamically sized array of data
int size; // Current size of our arraylist
public:
arraylist(); // Construct the arraylist
void add(T); // Add a new item to the list, should increment size
void remove(int); // Remove item at index, should decrement size
int find(T); // Given an item, find its index, return -1 if not found
int getSize(); // Return the current size of the arraylist
T * get(int); // Return a pointer to item at a int index
};
But the implementation seems to be giving me troubles.
template <class T> T* arraylist<T>::get(int idx) {
// Return a pointer to the item at idx index
if(idx > -1 && idx < size) return data[idx];
else return NULL;
}
And here is the file I'm using to test:
#include <iostream>
#include <string>
#include "arraylist.h"
using namespace std;
int main() {
string str1 = "foo";
string str2 = "bar";
string str3 = "baz";
string str4 = "qux";
arraylist<string> ar (); // Create an arraylist and construct it.
if(ar.get(5) != NULL) cout << "Something was returned!" << endl;
return 0;
}
Gnu C++ Compiler throws this error:
test-arraylist.cpp:15:16: error: request for member 'get' in 'ar', which is of n
on-class type 'arraylist<std::basic_string<char> >()'
I've been confused on this one for awhile now, but I guess its probably because I'm coming over to C++.
Could anyone help?


Sign In
Create Account


Back to top









