Hello everyone,

I practice in OOP in C. And I have difficulties to apply the function inside struct in the language c.

Here is for example a c++ code that I try to rewrite in language c.

Please can anyone tell me what is incorrect in this transcript?

Thank you in advance

class cp

{

public:

void Encode();

int Data(int * p);

private:

void Gf();

int m, n;

};

void cp::Encode()

{

m = 5; n = 31; // initialisierung

m += n-7;

}

void cp::Data(int *p)

{

for (int i=0; i<21; i++)

m[i]=p[i];

}

int cp::calculate()

{

cp m_cp;

int tmp, tmp2 ;

tmp2 = m_cp.Encode(tmp);

m_cp.data(tmp);

}

I have implemented as follows in c code.

typedef struct cp

{

int m,n,d[31];

void (*cp_Encode)();

int (* cp_Data)(int * p);

void (* cp_Gf)();

}cp;

cp m_cp; // as globale variable

void Encode()

{

m_cp.m = 5; m_cp.n = 31; // init variable

m_cp.m += m_cp.n-7;

}

void Data(int *p)

{

for (int i=0; i<21; i++)

m_cp.d[i] = p[i];

}

int calculate()

{

int tmp, tmp2 ;

m_cp.cpEncode = Encode;

m_cp.cpData = Data;

tmp2 = m_cp.cpEncode();

m_cp.cpdata(tmp);

}

greeting

Etie