Trying to understand tokens and classes
Jan 30, 2017 at 4:11pm UTC
I pretty much have no idea how classes work, so I'm just doing some trial and error. I'm trying to figure out how this class distinguishes kind from value. For some reason it says that I cannot use pushback on tok.
error: no matching function for call to 'std::vector<Token>::push_back(char&)'|
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
#include <iostream>
#include <vector>
using namespace std;
class Token
{
public :
char kind;
double value;
};
int main()
{
std::vector<Token> tok;
char ch;
std::cout << "Enter things to be tokenized" << std::endl;
for (int i = 0; i>10 ; i++)
{
std::cin >> ch,
tok.push_back(ch);
if (tok[i].kind =='*' )
{
std::cout << "is that a multiplication symbol?" << std::endl;
}
}
}
Jan 30, 2017 at 4:25pm UTC
You're trying to push a type Char into a type Token.
You'd probably want to have the Token Vector inside of the class.
You're also calling std:: when using namespace std;
Using namespace std removes the need to declare std:: calls
Which will get you a few more errors.
Jan 30, 2017 at 4:26pm UTC
Line 21 - do you mean for the middle condition to be i < 10
?
Topic archived. No new replies allowed.