I've created a class with a couple of variables in it. I can read these variables from my functions just fine. I seem to be able to update them to new values, however when I try to get the new values in the main() function it gives me the original values.
I'm sure it's something simple I'm missing, I just can't seem to figure it out.
header.h
#pragma once
#include <string>
#include "gmp.h"
class my_class {
public:
const static int CPU_GRP_SIZE = 16;
mpz_t tempx, tempy;
my_class()
{
mpz_init_set_str(tempx, "79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798", 16);
mpz_init_set_str(tempy, "483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8", 16);
}
};
void AddDirect(mpz_t p2x, mpz_t p2y);
main.cpp
#include <string>
#include <iostream>
#include <gmp.h>
#include "header.h"
void main()
{
my_class secp;
int hLength = (secp.CPU_GRP_SIZE / 2 - 1);
mpz_t point2x, point2y;
mpz_init_set_str(point2x, "c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5", 16);
mpz_init_set_str(point2y, "1ae168fea63dc339a3c58419466ceaeef7f632653266d0e1236431a950cfe52a", 16);
AddDirect(point2x, point2y);
std::cout << "+++++++++++++ main \n";
mpz_out_str(stdout, 16, secp.tempx);
std::cout << " \n";
}
void AddDirect(mpz_t p2x, mpz_t p2y)
{
my_class secp;
mpz_t point2x, point2y;
mpz_init_set(point2x, p2x);
mpz_init_set(point2y, p2y);
// ---------------------------
mpz_set(secp.tempx, point2x);
mpz_set(secp.tempy, point2y);
//------------------
std::cout << "adddirect secp.tempx\n";
mpz_out_str(stdout, 16, secp.tempx);
std::cout << " \n";
}
It shouldn't make any difference in this case, but I'm using visual studio 2022 on Windows 10.
Expected/wanted result:
adddirect secp.tempx
c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5
+++++++++++++ main
c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5
Real result:
adddirect secp.tempx
c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5
+++++++++++++ main
79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798