Hi Its my first time creating header file and accessing its variables in cpp. I have 2 files arrayyy.h and array.cpp and their code is mentioned below.
arrayyy.h
#ifndef ARRAYYY_H_
#define ARRAYYY_H_
namespace a {
class arrayyy {
public:
arrayyy();
virtual ~arrayyy();
private:
const static int num = 4;
int* arr = new int[num];
};
} /* namespace a */
#endif /* ARRAYYY_H_ */
arrayyy.cpp
#include "arrayyy.h"
#include "iostream"
using namespace std;
namespace a {
arrayyy::arrayyy() {
cout << a::arrayyy::num ;
a::arrayyy::arr = {8,2,9,4};
for(int i =0; i < a::arrayyy::num; i++)
{
cout << arr;
}
}
arrayyy::~arrayyy() {
}
//int main ()
//{
// cout << a::arrayyy::num ;
//}
} /* namespace a */
Instead of getting output CTD build console is showing following warnings
12:28:10 **** Incremental Build of configuration Debug for project TRiES ****
make all
Building file: ../src/arrayyy.cpp
Invoking: Cross G++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/arrayyy.d" -MT"src/arrayyy.o" -o "src/arrayyy.o" "../src/arrayyy.cpp"
In file included from ../src/arrayyy.cpp:8:0:
../src/arrayyy.h:19:24: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11
int* arr = new int[num];
^
../src/arrayyy.cpp: In constructor ‘a::arrayyy::arrayyy()’:
../src/arrayyy.cpp:19:28: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
a::arrayyy::arr = {8,2,9,4};
^
../src/arrayyy.cpp:19:18: error: cannot convert ‘<brace-enclosed initializer list>’ to ‘int*’ in assignment
a::arrayyy::arr = {8,2,9,4};
^
src/subdir.mk:18: recipe for target 'src/arrayyy.o' failed
make: *** [src/arrayyy.o] Error 1
12:28:10 Build Finished (took 417ms)
I've checked already asked questions but their answers are not helping me in this regard. I've used extern as well. Being a beginner I need guidance in this scenario. Please guide me to remove the warnings. Thank you.