#include <iostream>
using namespace std;
class test
{
public:
register int a;
};
int main() {
// your code goes here
test t;
t.a = 10;
return 0;
}
I am getting following error :
error: storage class specified for 'a'
Is there any way to use register storage class as member variable ?
According to storage duration:
The register specifier is only allowed for objects declared at block scope and in function parameter lists.
So you can't use it for class member variables.
Note, that this specifier is obsolete: it is deprecated since C++11 and totally removed since C++17 - just let the compiler do the optimizations.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With