I want to create class Test with const int variable with name "a". After that I need create constructor where variable "a" get value =10. I Create class test and in test.h I create const int a; in class Test.h and in test.cpp I have something like that:
#include "stdafx.h"
#include "Test.h"
Test::Test(void)
{
a = 10;
b = 20;
size = 20;
tekst[size];
}
Test::~Test(void)
{
}
and this is test.h:
#pragma once
class Test
{
const int a;
public:
Test(void);
~Test(void);
int b;
char *tekst;
int size;
static double d;
int y;
};
but I get error:
Error 1 error C2758: 'Test::a' : must be initialized in constructor base/member initializer list c:\users\bożydar\documents\visual studio 2012\projects\consoleapplication1\consoleapplication1\test.cpp 6
Error 2 error C2166: l-value specifies const object c:\users\bożydar\documents\visual studio 2012\projects\consoleapplication1\consoleapplication1\test.cpp 7