I have some basic template programming errors.
I have this code in main.cpp
:
#include <string>
#include <iostream>
#include "arrapp.h"
#include <algorithm>
#include <vector>
const int max = 1000;
int main()
{
int your_mark = 1;
/* 2-es*/
int s[] = {3, 2};
array_appender<int> ia ( s, sizeof( s ) / sizeof( s[ 0 ] ) );
for( int i = 0; i < max - 1; ++i )
{
ia.append( s, sizeof( s ) / sizeof( s[ 0 ] ) );
}
std::string hw[] = { "Hello", "World" };
std::string langs[] = { "C++", "Ada", "Brainfuck" };
std::string x[] = { "Goodbye", "Cruel", "World" };
array_appender<std::string> sa ( hw, sizeof( hw ) / sizeof( hw[ 0 ] ) );
sa.append( langs, sizeof( langs ) / sizeof( langs[ 0 ] ) );
sa.append( x, sizeof( x ) / sizeof( x[ 0 ] ) );
const array_appender<std::string> ha( hw, sizeof( hw ) / sizeof( hw[ 0 ] ) );
if ( max * 2 == ia.size() && 3 == ia.at( max ) && 2 == ia.at( 3 ) &&
&( s[ 0 ] ) == &(ia.at( max / 2 ) ) && 2 == ha.size() && 8 == sa.size() &&
"C++" == sa.at( 2 ) && 7 == sa.at( 5 ).length() && &( ha.at( 0 ) ) == hw )
{
your_mark = ia.at( max + 1 );
}
std::cout << "Your mark is " << your_mark;
std::endl( std::cout );
}
And I have to solve this, by writing "arrapp.h"
. So I created this:
#ifndef arrapp_H
#include <algorithm>
#include <list>
#include <vector>
#include <array>
template <typename T>
T const& array_appender (std::vector <T const&> v, T const& size) {
std::vector<T*> vec [size]= {};
for( int idx = 0; idx < size; ++idx)
{
std::cout << "value of v: " << v[idx] << std::endl;
vec.add(v[idx]);
}
return vec;
}
#endif // arrapp_H
But If I use this i got the error main.cpp|14|error: expected ';' before 'ia'|
. So this isn't working. How can I create these template things, to work? Am I misunderstood, here array_appender
don't have work as I think, as I wrote?