I'm trying to create two simple template classes where one of them
depends on the other to initialize its member integer variable. After
some time, I decided to post a message here because I don't really
understand why I can't make this work.

I guess that the error lies on the fact that a typedef is not an
instantiation of the object so therefore I cannot call the variable n
within ClassA. On the other hand, I cannot instantiate ClassA to
create the type definition of classB because I receive a compiler
error that tells me that the instantiated object of ClassA cannot
appear in a constant expression.

Is there a way around this? Maybe the solution is real simple. Thank
you.

I'm trying to create two simple template classes where one of them
depends on the other to initialize its member integer variable. After
some time, I decided to post a message here because I don't really
understand why I can't make this work.

I guess that the error lies on the fact that a typedef is not an
instantiation of the object so therefore I cannot call the variable n
within ClassA.

Right. You have a type, not an object, so there is no n_.

On the other hand, I cannot instantiate ClassA to create the type
definition of classB because I receive a compiler error that tells me that
the instantiated object of ClassA cannot appear in a constant expression.

Is there a way around this? Maybe the solution is real simple. Thank
you.

It depends on what you want to do. Maybe making n_ static is what you want.

I'm trying to create two simple template classes where one of them
depends on the other to initialize its member integer variable. After
some time, I decided to post a message here because I don't really
understand why I can't make this work.

template<int n>
class ClassA
{
public:
int n_;

static const int n_ = n;

// the original definition is a member variable. What you want is a
"static". It also likely needs to be const. You can use an anonymous enum.

I'm trying to create two simple template classes where one of them
depends on the other to initialize its member integer variable. After
some time, I decided to post a message here because I don't really
understand why I can't make this work.

template<int n>
class ClassA
{
public:
int n_;

static const int n_ = n;

// the original definition is a member variable. What you want is a
"static". It also likely needs to be const. You can use an anonymous enum.

ClassA() : n_(n)
{}

Nuke the constructor.
...

That worked!!!
However, I don't understand why, could you briefly explain me why is
working?

>>Hi everyone,I'm trying to create two simple template classes where one of themdepends on the other to initialize its member integer variable. Aftersome time, I decided to post a message here because I don't reallyunderstand why I can't make this work.template<int n>class ClassA{ public: int n_;

static const int n_ = n;

// the original definition is a member variable. What you want is a"static". It also likely needs to be const. You can use an anonymous enum.

>> ClassA() : n_(n) {}

Nuke the constructor....

That worked!!!
However, I don't understand why, could you briefly explain me why is
working?

Learn about "static" - it's one of the most overused keywords int the
language and means different things at different contexts.

-------------------

static const int A = 1; // use 1

struct T
{
static const int A = 1; // use 2

void f( int c )
{
static const int A = c; // use 3
}
};
--------------------
use 1 : this use of static is "deprecated". Anonymous namespaces is the
moral equivalent. In this use of static, A is only visible to the
compilation unit.

use 2 : This use indicates that there is only 1 instance of member A for
all classes and is initialized in global scope. When an integer type
POD is declared const above it may be used in constant expresssions
(declare the size of an array or use in template argument e.g.) non POD
static members must be initialized out of the class definition.

use 3 : static in a function block indicates there is only one A and
that it is initialized the first time control passes through the function.

Your fav. C++ reference book will have this fully described with
examples if it's worth anything.

>>aaragon wrote:Hi everyone,I'm trying to create two simple template classes where one of themdepends on the other to initialize its member integer variable. Aftersome time, I decided to post a message here because I don't reallyunderstand why I can't make this work.template<int n>class ClassA{ public: int n_; static const int n_ = n;

// the original definition is a member variable. What you want is a"static". It also likely needs to be const. You can use ananonymous enum.

ClassA() : n_(n) {}Nuke the constructor....

That worked!!!However, I don't understand why, could you briefly explain me why isworking?

Learn about "static" - it's one of the most overused keywords int the
language and means different things at different contexts.

-------------------

static const int A = 1; // use 1

struct T
{
static const int A = 1; // use 2

void f( int c )
{
static const int A = c; // use 3
}
};
--------------------
use 1 : this use of static is "deprecated". Anonymous namespaces is the
moral equivalent. In this use of static, A is only visible to the
compilation unit.

use 2 : This use indicates that there is only 1 instance of member A for
all classes and is initialized in global scope. When an integer type

..... I meant to write :
use 2 : This use indicates that there is only 1 instance of member A for
all OBJECTS of this class ...

POD is declared const above it may be used in constant expresssions
(declare the size of an array or use in template argument e.g.) non POD
static members must be initialized out of the class definition.

use 3 : static in a function block indicates there is only one A and
that it is initialized the first time control passes through the function.

Your fav. C++ reference book will have this fully described with
examples if it's worth anything.

aaragon wrote:Hi everyone,I'm trying to create two simple template classes where one of themdepends on the other to initialize its member integer variable. Aftersome time, I decided to post a message here because I don't reallyunderstand why I can't make this work.template<int n>class ClassA{ public: int n_;
static const int n_ = n;

// the original definition is a member variable. What you want is a
"static". It also likely needs to be const. You can use an anonymous enum.

> ClassA() : n_(n) {}
Nuke the constructor.
...

That worked!!!
However, I don't understand why, could you briefly explain me why is
working?

Learn about "static" - it's one of the most overused keywords int the
language and means different things at different contexts.

-------------------

static const int A = 1; // use 1

struct T
{
static const int A = 1; // use 2

void f( int c )
{
static const int A = c; // use 3
}};

--------------------
use 1 : this use of static is "deprecated". Anonymous namespaces is the
moral equivalent. In this use of static, A is only visible to the
compilation unit.

use 2 : This use indicates that there is only 1 instance of member A for
all classes and is initialized in global scope. When an integer type
POD is declared const above it may be used in constant expresssions
(declare the size of an array or use in template argument e.g.) non POD
static members must be initialized out of the class definition.

use 3 : static in a function block indicates there is only one A and
that it is initialized the first time control passes through the function.

Your fav. C++ reference book will have this fully described with
examples if it's worth anything.

>>Hi everyone,I'm trying to create two simple template classes where one of themdepends on the other to initialize its member integer variable. Aftersome time, I decided to post a message here because I don't reallyunderstand why I can't make this work.template<int n>class ClassA{ public: int n_;

static const int n_ = n;

// the original definition is a member variable. What you want is a"static". It also likely needs to be const. You can use an anonymous enum.

>> ClassA() : n_(n) {}

Nuke the constructor....

That worked!!!
However, I don't understand why, could you briefly explain me why is
working?

CORRECTED VERSION - cancelling previous version...

Learn about "static" - it's one of the most overused keywords int the
language and means different things at different contexts.

-------------------

static const int A = 1; // use 1

struct T
{
static const int A = 1; // use 2

void f( int c )
{
static const int A = c; // use 3
}
};
--------------------
use 1 : this use of static is "deprecated". Anonymous namespaces is the
moral equivalent. In this use of static, A is only visible to the
compilation unit.

use 2 : This use indicates that there is only 1 instance of member A for
all objects of this class and is initialized in global scope which makes
A in this use globally accessible. When an integer type POD is declared
const like above it may be used in constant expresssions (declare the
size of an array or use in template argument e.g.) non POD static
members must be initialized out of the class definition.

use 3 : static in a function block indicates there is only one A and
that it is initialized the first time control passes through the function.

Your fav. C++ reference book will have this fully described with
examples if it's worth anything.

It appears that after all these years, there are still bugs in
cancelling messages ! I don't think I have ever seen it work. We'll
try again in another 5 years.

Because of the large number of forged cancels, I believe that
most sites today simply ignore them. (They worked, for me,
fifteen years ago. But not now.)

I don't think it ever worked for me - can't they use a PKI type auth ?

[This is getting awfully off topic...]

In theory, there are any number of solutions which could be
used. In practice, the mass of systems out there is now too
large to start playing with the protocol; add any formal
authentication, and it will be years before all, or even most,
of the systems will support it.

Anyway, I did successfully cancel some messages I'd posted back
in the early 1990's.