> C++ Template Help?

C++ Template Help?

Posted at: 2014-12-18 
Check whether this is helpful:

http://msdn.microsoft.com/en-us/library/...

#include

int main () {

std::magic();

}

I'm having a hard time understanding the instructions and why I'm getting an error. Here is the instructions for this function

getElementAt

o Returns an element at a given index

? The index is passed as an integer

? The return value is a constant and it is returned as a reference

Here is the code for the function:

template

int DArray::getElementAt(int idx) const

{



}

This is the error I get from the compiler:

1>e:\cs 250\wk 6\ex_10_darray_template\project\main.cpp(162): error C2228: left of '.print' must have class/struct/union

1> type is 'int'

and here is the line the error refers too:

//Print array

int usedArray = objectArray.getNumberUsed();

cout << "\nArray of objects:\n";

for (int i = 0; i < usedArray; ++i)

(objectArray.getElementAt(i)).print();

I've tried multiple things in the function but I get the same error. If anyone can point me in the right direction it would be appreciated. Thank you.