Good Evening (in CET) to everyone.
I am in need of a bit of help.
I have the following cpp and.h files:
dirmain.cpp
#include "dirseq.h"
#include <iostream>
#include <algorithm>
#include "dirseq.h"
#include <string>
struct IsEven
{
bool operator()( int i ) const
{
return i % 2 == 0;
}
};
const int max = 1024;
int main()
{
int yourMark = 1;
DirectionSequence<int> di;
di.push_back( 1 );
di.push_back( 2 );
di.push_back( 5 );
const DirectionSequence<int> cdi = di;
di.change_direction();
di.push_back( 3 );
di.push_back( 7 );
DirectionSequence<std::string> ds;
ds.push_back( "Test" );
DirectionSequence<double> x;
for( int i = 0; i < max; ++i )
{
x.push_back( i / 10.0 );
x.change_direction();
}
if( 1 == cdi.at( 0 ) &&
5 == di.at( 0 ) &&
100.5 < x.at( 1 ) &&
4 == ds.at( 0 ).length() )
{
yourMark = di.size() - cdi.size();
}
dirseq.h
#ifndef DIR_H
#define DIR_H
#include <iostream>
#include <string>
template <class D>
class DirectionSequence
{
public:
DirectionSequence();
void push_back(const D ad);
void change_direction();
const D at(const int vp);
int size();
private:
D v;
int vp;
int tn;
int als,fels;
D temp;
template <class T>
DirectionSequence()
{
v= new D[1024];
vp=0;
tn=0;
};
template <class T>
void push_back(const D ad)
{
if (tn<1024)
{v[vp++]= ad;
tn++;}
else std::cout<<"megtelt a verem.";
}
template <class T>
const D at(const int vp)
{
return (v[vp]);
}
template <class T>
int size(D ad)
{
return tn;
}
template <class T>
void change_direction()
{
als=0;
fels=tn;
while (als<=fels)
{
temp=v[als];
v[als]=v[fels];
v[fels]=temp;
als++;
fels--;
}
}
};
#endif
The Cpp file cannot be modified!
The errors:
g:\herpaai\dirmain.cpp|37|error: passing 'const DirectionSequence<int>' as 'this' argument of 'const D DirectionSequence<D>::at(int) [with D = int]' discards qualifiers|
g:\herpaai\dirmain.cpp|42|error: passing 'const DirectionSequence<int>' as 'this' argument of 'int DirectionSequence<D>::size() [with D = int]' discards qualifiers|
where have I gone wrong?
Thank you for the help.