A
Aaron Gray
I am trying to declare a const in a header file but have forgetten how.
I have a class and I want a Null value for that struct to pass as an
argument when it is not being used. Now it used to be done passing a '0',
but the class now has an iheriting child class e.g. :-
class A {...}
fn( ..., A a, ...)
and
fn( ..., 0, ...)
But now we have :-
class B : public A {...}
and fn(..., 0, ...) is declaring that parameter 2 is now ambiguous.
So what I wanted was to declare a 'NullA'.
But it has to be declared in a header and there are multiple C++ files using
the header and they all get linked to gether. So declaring in the header :-
const NullA* = 0;
is out.
The only way I have found is :-
class A {
public:
const Null;
};
then is one C++ file :-
const A::Null = 0;
and
fn( ..., A::Null, ...)
But the 'A' name is rather long and I would have prfered an out of class
solution with A's acronym.
I am probably forgetting something very basic about C++.
Any help welcome,
Aaron
I have a class and I want a Null value for that struct to pass as an
argument when it is not being used. Now it used to be done passing a '0',
but the class now has an iheriting child class e.g. :-
class A {...}
fn( ..., A a, ...)
and
fn( ..., 0, ...)
But now we have :-
class B : public A {...}
and fn(..., 0, ...) is declaring that parameter 2 is now ambiguous.
So what I wanted was to declare a 'NullA'.
But it has to be declared in a header and there are multiple C++ files using
the header and they all get linked to gether. So declaring in the header :-
const NullA* = 0;
is out.
The only way I have found is :-
class A {
public:
const Null;
};
then is one C++ file :-
const A::Null = 0;
and
fn( ..., A::Null, ...)
But the 'A' name is rather long and I would have prfered an out of class
solution with A's acronym.
I am probably forgetting something very basic about C++.
Any help welcome,
Aaron