1
edit
Changes
→C/C++ FAQ
<br>
'''A:''' Any of the stated syntaxes are acceptable for passing a 2D array into a function. Generally the 2nd syntax (array[][COLS]) is used if the array is static and the number of cols is known. This is in order to reveal the preferred structure to the compiler, since the compiler stores a 2D array as one really long array with arrays as its elements. For example an array[3][3] would looks something like this in memory '''|''' |||| '''|''' |||| '''|''' |||| '''|''' where as we perceive the structure as a table. The other 2 syntaxes are equivalent and are generally used to pass a 2D array into a function if the structure is not know, hence for dynamic created arrays.
<br>'''Submitted by:''' Team 6 <br><br>
----
<br><br>
'''Q:''' When creating the header file for a template class and putting the implementation in the header as well there are no errors. However when splitting the deceleration (header) and implementation (making a cpp file) for that class template there are numerous compile errors. What do all these errors mean?
<br>
'''A:''' When splitting the deceleration of a template class additional code must be added onto every member of that class. If one has a class called Stack and a function called add(int x) for example, then in the implementation file the display function would be defined in the scope of the Stack class by writing int Stack::add(int x). Since templates are being used the compiler must also be told that this implementation is being defined with a template. This is done by writing something like template<class T> before every function. For the example stated it would look like this:
template<class T>
int Stack<T>::add(T x)
<br>'''Submitted by:''' Team 6 <br><br>
----