Two equal examples, but can not compile second

G

Grizlyk

Hello.

I am thinking: why if i will comment lines marked with '#' in the following
example, all will be compiled, else will not:


// ***********************
typedef unsigned uint;

namespace Pxx{
template <
class Tobj,
class c_Second,
class Tuint=uint
class First
{
public:
typedef c_Second Second;
typedef typename c_Second::Third Third; //#1
typedef typename c_Second::Forth Forth; //#2

First(){}
inline explicit First(const Tuint);

public:
class Tfriend
{
public:

public:
mutable First *parent;

void
operator= (const First *const p)const
{ parent=const_cast<First*>(p); }

Tfriend():parent(0){}
Tfriend(const First& p):
parent(const_cast<First*>(&p))
{}
};

};}

// ***********************
namespace Pxx{
template <
class Tobj,
class c_First,
class c_Forth,
class c_Third,
class Tuint=uint
class Second
{
public:
typedef c_First First;
typedef c_Forth Forth;
typedef c_Third Third;

//derived Second
typedef typename c_First::Second c_Second;

Second(){}
inline Second(const First&);
};}


// ***********************
// ***********************
namespace Pxx{
namespace Puser{

// ***********************
template <class Tobj,class Tuint> class First;
template <class Tobj,class Tuint> class Second;
template <class Tobj,class Tuint> class Third;
template <class Tobj,class Tuint> class Forth;

// ***********************
template <
class Tobj,
class Tuint=uint
class First:
public Pxx::First<
Tobj,
Second said:
{
typedef Pxx::First<
Tobj,
Second said:
Tparent;
public:
typedef typename Tparent::Second Second;

First(){}
explicit First(const Tuint p):Tparent(p){}
};

// ***********************
template <
class Tobj,
class Tuint=uint
class Second:
public Pxx::Second<
Tobj,
First<Tobj,Tuint>,
Forth<Tobj,Tuint>,
Third said:
{
typedef Pxx::Second<
Tobj,
First<Tobj,Tuint>,
Forth<Tobj,Tuint>,
Third said:
Tparent;

public:
typedef typename Tparent::First First;

Second(){}
Second(const First& p):Tparent(p){}
};


//namespace Puser
}
//namespace Pxx
}
using Pxx::puser::First;
using Pxx::puser::Second;


// ***********************
// ***********************
First<int> first(100);
Second<int> second(first);

=============
Output

11.cpp: In instantiation of
'Pxx::Second<int,
Pxx::puser::First<int, unsigned int>,
Pxx::puser::Forth<int, unsigned int>,
Pxx::puser::Third<int, unsigned int>,
unsigned int>':
11.cpp:113: instantiated from
'Pxx::puser::Second<int, unsigned int>'
11.cpp:14: instantiated from
'Pxx::First<int,
Pxx::puser::Second<int, unsigned int>,
unsigned int>'
11.cpp:86: instantiated from
'Pxx::puser::First<int, unsigned int>'
11.cpp:141: instantiated from here
11.cpp:57: error: no type named 'Second' in 'class
11.cpp:57: error: Pxx::puser::First<int, unsigned int>'


--
Maksim A. Polyanin
http://grizlyk1.narod.ru/cpp_new

"In thi world of fairy tales rolls are liked olso"
/Gnume/
 
A

Alf P. Steinbach

* Grizlyk:
Hello.

I am thinking: why if i will comment lines marked with '#' in the following
example, all will be compiled, else will not:


// ***********************
typedef unsigned uint;

namespace Pxx{
template <
class Tobj,
class c_Second,
class Tuint=uint
class First
{
public:
typedef c_Second Second;
typedef typename c_Second::Third Third; //#1
typedef typename c_Second::Forth Forth; //#2

Well I have something cooking so no time to look at yer code, but most
probably it's a dependent type and a missing 'typename' or 'template'
keyword.

Check it out & come back.
 
J

Jerry Coffin

Hello.

I am thinking: why if i will comment lines marked with '#' in the following
example, all will be compiled, else will not:

At least offhand, I don't see any reason your code shouldn't compile. I
suspect you've run into a bug in your compiler.
 
G

Grizlyk

Grizlyk said:
I am thinking: why if i will comment lines marked with '#' in the
following example, all will be compiled, else will not:

No one knows why it can not be compiled, but some men have offered me to use
separated class for crossed type declarations. Now the example can be
compiled with class "Types":


// ***********************
typedef unsigned uint;

namespace Pxx{
template <
class Tc_obj,
class Tc_First,
class Tc_Second,
class Tc_Third,
class Tc_Fourth,
class Tc_Tuint=uint
class Types
{
public:

typedef Tc_obj Tobj;
typedef Tc_First First;
typedef Tc_Second Second;
typedef Tc_Third Third;
typedef Tc_Fourth Fourth;
typedef Tc_Tuint Tuint;

};}

namespace Pxx{
template <
class Tc_types
class First
{
public:

typedef typename Tc_types::Tobj Tobj;
typedef typename Tc_types::Second Second;
typedef typename Tc_types::Third Third;
typedef typename Tc_types::Fourth Fourth;
typedef typename Tc_types::Tuint Tuint;

//derived First
typedef typename Tc_types::First Tc_First;

First(){}
inline explicit First(const Tuint);

public:
class Tfriend
{
public:

public:
mutable First *parent;

void
operator= (const First *const p)const
{ parent=const_cast<First*>(p); }

Tfriend():parent(0){}
Tfriend(const First& p):
parent(const_cast<First*>(&p))
{}
};

};}

namespace Pxx{
template <
class Tc_types
class Second
{
public:

typedef typename Tc_types::Tobj Tobj;
typedef typename Tc_types::First First;
typedef typename Tc_types::Third Third;
typedef typename Tc_types::Fourth Fourth;
typedef typename Tc_types::Tuint Tuint;

//derived Second
typedef typename Tc_types::Second Tc_Second;

Second(){}
inline Second(const First&);
};}


// ***********************
namespace Pxx{
namespace Puser{

template <class Tobj,class Tuint> class First;
template <class Tobj,class Tuint> class Second;
template <class Tobj,class Tuint> class Third;
template <class Tobj,class Tuint> class Fourth;

template <
class Tc_obj,
class Tc_uint
class Types:
public Pxx::Types<
Tc_obj,
First<Tc_obj,Tc_uint>,
Second<Tc_obj,Tc_uint>,
Third<Tc_obj,Tc_uint>,
Fourth said:
{
public:
};

template <
class Tc_obj,
class Tc_uint=uint
class First:
public Pxx::First<
Types said:
{
typedef Pxx::First<
Types said:
Tparent;
public:
typedef typename Tparent::Tuint Tuint;

First(){}
explicit First(const Tuint p):Tparent(p){}
};

template <
class Tc_obj,
class Tc_uint=uint
class Second:
public Pxx::Second<
Types said:
{
typedef Pxx::Second<
Types said:
Tparent;

public:
typedef typename Tparent::First First;

Second(){}
Second(const First& p):Tparent(p){}
};


//namespace Puser
}
//namespace Pxx
}
using Pxx::puser::First;
using Pxx::puser::Second;


// ***********************
First<int> first(100);
Second<int> second(first);


--
Maksim A. Polyanin
http://grizlyk1.narod.ru/cpp_new

"In thi world of fairy tales rolls are liked olso"
/Gnume/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,997
Messages
2,570,241
Members
46,830
Latest member
HeleneMull

Latest Threads

Top