How to call a method within the class?

Asked

Viewed 616 times

1

I’m trying to call the method that returns a unsigned char through another method of the same class, I reviewed the whole internet but did not understand how to do it.

byte CryrazCore::*ComputeByteArray(byte inputData[], bool decryptMode)
{
    int cs = this->CryrazCore::PushChecksum();
}

The method I’m trying to call is called CryrazCore::PushChecksum(), this is his statement:

// CryrazCore.cpp
byte CryrazCore::PushChecksum()
// CryrazCore.h
byte PushChecksum();

Here’s what it says on the bug, on the line of the first question code.

'this': can only be referenced Inside non-static Member functions or non-static data Member initializers

Where I’m going wrong to call the function?

  • 1

    What would that asterisk be on ::*? If it were to make a pointer to byte shouldn’t he be next to the type? What if the return of the method is byte, why the variable cs is the type int?

  • As I said, I am new. I know almost nothing in this language, I put the ::* hoping to be a so-called "static", but I think it’s all wrong kkk

  • The pointer *byte would be the same thing as ref byte in C#, no?

1 answer

1


This code doesn’t even compile for other reasons either. Probably it would be like this:

byte *CryrazCore::ComputeByteArray(byte inputData[], bool decryptMode) {
    int cs = this->PushChecksum();
    //deveria usar os parâmetros
    return alguma coisa que seja um ponteiro para byte;
}

I put in the Github for future reference.

You have to decide whether to use this-> or CryrazCore::, both do not. The first calls the instance, which seems to be the case, the second calls a static member.

Try to make simple examples before you start making complex ones.

  • The return of PushChecksum is the type byte, but cs is as int. That one cast would it be possible? If so, why the type byte is less than int or use has no relation?

  • @Andersoncarloswoss the return is byte*, the cast is possible, generally speaking, C/C++ has a complicated specification to suit all architectures, but unlikely to be that intention. The rest became meaningless because you started from wrong information. It is possible because in practice a pointer can usually be represented by int, although it is not valid for all architectures. The whole code is very wrong and makes little sense.

  • The method ComputeByteArray returns the pointer, but PushChecksum It doesn’t look like it. Correct me if I’m wrong, please.

  • 1

    That, and what’s the problem?

  • I don’t know. I wondered if byte return could be stored in the int without problems. You said yes, because usually the pointer can be stored in the int, but the return is by value, not a pointer. This does not influence?

  • That I can’t even say 'cause I don’t know the guy byte iso should be a code definition, not part of C++. The return must be a pointer, it must have put the pointer in the wrong place, it is usually a pointer. I imagine that byte actually be a char internally, and it’s rare to return it. If none of this is true, the AP has to say. Only he understands this code, I gave the solution to the specific problem, all other problems depends on what the real code is, this requires speculation to fix. I even tried. That’s why I said I don’t even compile for other reasons.

  • The byte type is a using byte = unsigned char;.

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.