Daniel T. said:
What's the first error the compiler give you and what line does it point
to?
the code and the error are as listed ( thank you for helping
)
**************** statistics.h ****************
#ifndef STATISTICS_H
#define STATISTICS_H
#include <vector>
using std::vector;
#include <map>
using std::map;
class count_consecutive : public unary_function< char, void >
{
public:
char comp;
unsigned count;
unsigned max_count;
count_consecutive(char value);
~count_consecutive();
void operator()(char c);
unsigned result();
};
class statistics
{
map<char, int> mp;
vector<char> v;
void stock_take();
int bigest_r(vector<char> const& cv);
public:
statistics(vector<char> const& cv);
~statistics();
map<char,int> get_counts;
};
#endif
**************** statistics.cpp ****************
#include <vector>
using std::vector;
#include <algorithm>
using std::count;
#include "statistics.h"
count_consecutive::count_consecutive( char value )
: comp( value )
, count( 0 )
, max_count( 0 )
{ }
void count_consecutive:
perator()( char c ) {
if ( c == comp )
++count;
else {
max_count = max( count, max_count );
count = 0;
}
}
unsigned count_consecutive::result() const {
return max( count, max_count );
}
statistics::statistics(vector<char> const& cv)
: v( cv )
{
statistics::stock_take();
}
void statistics::stock_take()
{
mp['c'] = count(v.begin(), v.end(), 'c');
mp['r'] = bigest_r(v);
}
int statistics::bigest_r(vector<char> const& cv)
{
int k = for_each( cv.begin(), cv.end(),
count_consecutive( 'd' ) ).result();
return k;
}
**************** statistics_test.cpp ****************
#include <iostream>
using std::cout;
#include <vector>
using std::vector;
#include "statistics.h"
int main() {
vector v = {c r r r d x c c d d d d k};
statistics st1(v);
cout << "c" << (st1.get_counts)[c]
<< "r" << (st1.get_counts)[r]
<< '\n';
}
**************** error ****************
$ make
g++ -c -o statistics.o statistics.cpp
statistics.h:9: error: expected template-name before '<' token
statistics.h:9: error: expected `{' before '<' token
statistics.h:9: error: expected unqualified-id before '<' token
statistics.cpp:10: error: invalid use of undefined type 'class count_consecutive'
statistics.h:9: error: forward declaration of 'class count_consecutive'
statistics.cpp: In constructor 'count_consecutive::count_consecutive(char)':
statistics.cpp:11: error: class 'count_consecutive' does not have any field named 'comp'
statistics.cpp:12: error: class 'count_consecutive' does not have any field named 'count'
statistics.cpp:13: error: class 'count_consecutive' does not have any field named 'max_count'
statistics.cpp: At global scope:
statistics.cpp:16: error: invalid use of undefined type 'class count_consecutive'
statistics.h:9: error: forward declaration of 'class count_consecutive'
statistics.cpp: In member function 'void count_consecutive:
perator()(char)':
statistics.cpp:17: error: 'comp' was not declared in this scope
statistics.cpp:18: error: no pre-increment operator for type
statistics.cpp:20: error: 'max_count' was not declared in this scope
statistics.cpp:20: error: 'max' was not declared in this scope
statistics.cpp:21: error: overloaded function with no contextual type information
statistics.cpp: At global scope:
statistics.cpp:25: error: invalid use of undefined type 'class count_consecutive'
statistics.h:9: error: forward declaration of 'class count_consecutive'
statistics.cpp: In member function 'unsigned int count_consecutive::result() const':
statistics.cpp:26: error: 'max_count' was not declared in this scope
statistics.cpp:26: error: 'max' was not declared in this scope
statistics.cpp: In member function 'int statistics::bigest_r(const std::vector<char, std::allocator<char> >&)':
statistics.cpp:47: error: invalid use of undefined type 'class count_consecutive'
statistics.h:9: error: forward declaration of 'class count_consecutive'
make: *** [statistics.o] Error 1
fred@debian:~/myPrograms/backtest$