Getting expression must have class type error as well as invalid types error. (Multithreading)

Hello, I'm getting an error with my program when using maps with pointers. For context, I'm trying to calculate the frequency of each character in a string that I got from the input file. Note that I am trying to implement multithreading as well. Any suggestions on fixing this error?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
struct variables{

    char symbol;
    int freq; 
    string code;
    string* pointerContent;

};

void* frequency(void* inputContents){

    struct variables* contents = (struct variables*) inputContents;

    /*Step (2)*/
    std::map<char, int> priorityMap; 
    std::map<char, int>::iterator priorityItr;

    for(long j = 0; j < (contents->pointerContent->length()); j++){
        priorityMap[(contents->pointerContent).at(j)++]; //expression must have class type & invalid types ‘char[long int]’ for array subscript
    }
Last edited on
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
34
35
36
37
38
39
40
41
42
#include <iostream>
#include <string>
#include <map>
using namespace std;

struct variables
{
    char symbol;
    int freq; 
    string code;
    string* pointerContent;
};

void* frequency(void* inputContents)
{
    variables* contents = static_cast<variables*>(inputContents);
    std::map<char, int> priorityMap; 

    for (size_t j = 0; j < contents->pointerContent->size(); ++j)
        ++priorityMap[(*contents->pointerContent)[j]];
        // OR ++priorityMap[contents->pointerContent->at(j)];

    for (const auto& e: priorityMap)
        cout << e.first << ' ' << e.second << '\n';

    return nullptr;
}

int main()
{
    variables v
    {
        'a',
        42,
        "abcde",
        new string("hello")
    };
    
    frequency(static_cast<void*>(&v));

    delete v.pointerContent;
}
Topic archived. No new replies allowed.