return value class

hi there again

I have a class and when I call it, it does change a global variable gtest without any problem but it does not return the test value.

Form1.h
CRC12 dfs;
retval = dfs.CHECK(one,two); // retval will never be set



serial.h
class CRC12 {

public:

unsigned int x;
CRC12 (void)
{

x = 69;
}



unsigned char CHECK (unsigned char cPrev, unsigned char cNext)
{
unsigned int test = 81;
gtemp = 98;
return test;
}
};
Your function promises to return an unsigned char unsigned char CHECK (unsigned char cPrev, unsigned char cNext) but then you try to return an unsigned int. Which is it meant to be?
nah it is the same for unsigned char
It works fine. Perhaps you're pushing the wrong button to compile it.

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
#include <iostream>

int gtemp = 5;

class CRC12 {
public:

unsigned int x;
CRC12 ()
{
x = 69;
}



unsigned char CHECK (unsigned char cPrev, unsigned char cNext)
{
unsigned char test = 81;
gtemp = 98;
return test;
}
}; 


int main()
{
  CRC12 dfs;
  unsigned char one, two, retval;
  retval = 80;
  
  std::cout << "retval before = " << retval << std::endl;
  retval = dfs.CHECK(one,two);
  std::cout << "retval after  = " << retval;
  
}

Last edited on
Thank you Moschops I don't know why but I must have overlooked something for the last days.

many thanks !!!!!!
Topic archived. No new replies allowed.