I'm fairly new to C++, and I'm having problems when compiling this program, any help with any of the error would be appreciated
Error list:
operator.h(9): error C2011: 'Operator' : 'class' type redefinition
operator.h(9) : see declaration of 'Operator'
operator.cpp(11): error C2027: use of undefined type 'Operator'
operator.h(9) : see declaration of 'Operator'
operator.cpp(11): error C2146: syntax error : missing ')' before identifier 'filename'
operator.cpp(11): error C2146: syntax error : missing ';' before identifier 'filename'
operator.cpp(11): error C2079: 'string' uses undefined class 'Operator'
operator.cpp(11): error C2059: syntax error : ')'
operator.cpp(12): error C2470: 'filename' : looks like a function definition, but there is no parameter list; skipping apparent body
operator.cpp(20): error C2027: use of undefined type 'Operator'
\operator.h(9) : see declaration of 'Operator'
operator.cpp(24): error C2065: 'Frequency' : undeclared identifier
operator.cpp(25): error C3312: no callable 'begin' function found for type ''unknown-type''
operator.cpp(25): error C3312: no callable 'end' function found for type ''unknown-type''
main.cpp(8): error C2079: 'myOperatorObject' uses undefined class 'Operator'
main.cpp(8): error C2440: 'initializing' : cannot convert from 'const char [15]' to 'int'
1> There is no context in which this conversion is possible
main.cpp(10): error C2228: left of '.getCharFrequency' must have class/struct/union
1> type is 'int'
Operator.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
#include <map>
#include <cstddef>
//using namespace std;
#include "Operator.h"
Operator::Operator(string filename)
{
ifstream infile;
int i = 0;
infile.open(filename.c_str());
getline(infile,Frequency);
infile.close();
}
std::map<char, std::size_t> Operator::getCharFrequency()
{
int c;
std::map<char, std::size_t> freq;
for(auto c: Frequency)
{
if( freq.find(c) == freq.end())
freq[c] = 1;
else
++freq[c];
}
return freq;
}
|
Operator.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
#include <map>
#include <cstddef>
using namespace std;
// Define class:
class Operator {
public:
//Constructor
Operator(string filename);
//a function that does the job
std::map<char, std::size_t> getCharFrequency();
private:
//private variable the class is working with
string Frequency;
};
|
main.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
#include "stdafx.h"
#include "Operator.h"
#include "Operator.cpp"
int main()
{
//instatntiate an "Operator" by calling the Constructor
Operator myOperatorObject("richardiii.txt");
//use the function to get the Char-Frequency Map
std::map<char, std::size_t> freq = myOperatorObject.getCharFrequency();
//do whatever you want with it
for(auto elem: freq)
std::cout << elem.first << " -> " << elem.second << std::endl;
}
|
Thanks in advance