I get the error error: ‘Name’ was not declared in this scope
What am I missing here.
Source File:
#include<iostream>
#include "scr.h"
using namespace std;
const char* const Test::Name;
void Test::Print()
{
cout<<Name;
}
int main()
{
Test *t = new Test();
t->Print();
delete t;
}
Header File:
class Test
{
static const char* const Name = "Product Name";
public:
void Print();
};
EDIT:
If I replace char* const with int, it works. Why?
static const int Name = 4; //in header
const int Test::Name; //In source
The purpose of the code is to have an alternate for #define as mentioned in Effective C++. In the example there, static const int is used.