below I have a class
#include <iostream>
#include <vector>
using namespace std;
class Car
{
public:
static int b;
static char* x1(int x)
{
b=x;
return (char *)"done";
}
};
in main
int main()
{
char* ret = Car::x1(42);
for(int x=0;x<4;x++)
{cout<<ret[x]<<endl;}
return 0;
}
but I am getting following error
/usr/bin/ld: /tmp/ccRfvgz8.o: warning: relocation against `_ZN3Car1bE' in read-only section `.text._ZN3Car2x1Ei[_ZN3Car2x1Ei]'
/usr/bin/ld: /tmp/ccRfvgz8.o: in function `Car::x1(int)':
main.cpp:(.text._ZN3Car2x1Ei[_ZN3Car2x1Ei]+0xc): undefined reference to `Car::b'
/usr/bin/ld: warning: creating DT_TEXTREL in a PIE
collect2: error: ld returned 1 exit status
Update
after the comment by Serge Balesta I changed x1 function to include Car::b=x;
but I get this error
/usr/bin/ld: /tmp/ccjMKe4u.o: warning: relocation against `_ZN3Car1bE' in read-only section `.text._ZN3Car2x1Ei[_ZN3Car2x1Ei]'
/usr/bin/ld: /tmp/ccjMKe4u.o: in function `Car::x1(int)':
main.cpp:(.text._ZN3Car2x1Ei[_ZN3Car2x1Ei]+0xc): undefined reference to `Car::b'
/usr/bin/ld: warning: creating DT_TEXTREL in a PIE
collect2: error: ld returned 1 exit status
updated function
static char* x1(int x)
{
Car::b=x;
return (char *)"done";
}