0
class automat_finit
{
    int CxQ, CxF, CxSigma, CxTranzitii, q0, SC, *F;
    char *Sigma;

    struct delta
    {
        int a1, a2;
        char c;
    }*G;

public:
    int tranzitie(int x, char c)
    {
        for(int i = 0; i < CxTranzitii; i++)
            if((G[i].a1 == x) && (G[i].c == c))
                return G[i].a2;
        return -1;
    }

    automat_finit()
    {
        ifstream f("automatfinit.in");
        SC = 0;
        f >> CxQ;
        F = new int[CxF];
        for(int i = 0; i < CxF; i++)
            f >> F[i];
        Sigma = new char[CxSigma];
        for(int i = 0; i < CxSigma; i++)
            f >> Sigma[i];
        f >> CxTranzitii;
        G = new delta[CxTranzitii];
        for(int i = 0; i < CxTranzitii; i++)
            f >> G[i].a1 >> G[i].c >> G[i].a2;
        f.close();
    }

    bool citire(char *cuvant)
    {
        int l = strlen(cuvant);
        for(int i = 0; i < l; i++)
        {
            SC = tranzitie(SC, cuvant[i]);
            if(SC == -1) return false;
        }
        for(int i = 0; i < CxF; i++)
            if(SC == F[i]) return true;
        return false;
    }
};

int main()
{
    automat_finit A();
    char w[100];
    cin>>w;
    if(A.citire(w) == true) cout<<"Word accepted"<<endl;
    else cout<<"Word denied"<<endl;
}

I get an error in main on line 64 with the 'citire' method, and I don't know why. It says

error: request for member 'citire' in 'A', which is of non-class type 'automat_finit()'.

Also, if I declare object A instead of A(), I get bad alloc error. Why is that?

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • Also, the large list of linked questions [here](https://stackoverflow.com/q/180172/1896169) which could also be duplicate targets – Justin Mar 29 '18 at 23:18
  • For the next error: You input `CxQ`, but then use `CxF` and `CxSigma` for array sizes. What are those values? – Bo Persson Mar 29 '18 at 23:36

2 Answers2

0

It says "error: request for member 'citire' in 'A', which is of non-class type 'automat_finit()'.

It's what it says. automat_finit A() declares a function, not an object.

If I declare object A instead of A()

Correct fix.

I get bad alloc error. Why is that?

Because you have a bad allocation somewhere. Time to debug! Check your allocations. Check your news. Check the variables you use to bound your news. For example, where did you give CxF a meaningful value?

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
0

automat_finit A(); declares a function named A that returns an automat_finit object. If you want to declare an object named A of type automat_finit, you need to remove the panthesis:

automat_finit A;

As for the resulting memory allocation error, your CxF and CxSigma members are uninitialized when used by the F = new int[CxF] and Sigma = new char[CxSigma] statements, respectively. Uninitialized class members have indeterminate values (unless the object is allocated in global memory, which is not the case in your situation). By default, the new operator throws a std::bad_alloc exception when it fails to allocate the requested amount of memory. Your members likely contain very large values by default, which you are not overwriting.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770