By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,190 Members | 967 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,190 IT Pros & Developers. It's quick & easy.

Two equal examples, but can not compile second

P: n/a
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 Tuintclass First;
template <class Tobj,class Tuintclass Second;
template <class Tobj,class Tuintclass Third;
template <class Tobj,class Tuintclass Forth;

// ***********************
template <
class Tobj,
class Tuint=uint
>
class First:
public Pxx::First<
Tobj,
Second<Tobj,Tuint>,
Tuint
>
{
typedef Pxx::First<
Tobj,
Second<Tobj,Tuint>,
Tuint
>
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<Tobj,Tuint>,
Tuint
>
{
typedef Pxx::Second<
Tobj,
First<Tobj,Tuint>,
Forth<Tobj,Tuint>,
Third<Tobj,Tuint>,
Tuint
>
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<intfirst(100);
Second<intsecond(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/
Mar 10 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
* 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.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Mar 10 '07 #2

P: n/a
In article <es**********@aioe.org>, gr******@yandex.ru says...
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.

--
Later,
Jerry.

The universe is a figment of its own imagination.
Mar 10 '07 #3

P: n/a

Grizlyk wrote:
>
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 Tuintclass First;
template <class Tobj,class Tuintclass Second;
template <class Tobj,class Tuintclass Third;
template <class Tobj,class Tuintclass 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<Tc_obj,Tc_uint>,
Tc_uint
>
{
public:
};

template <
class Tc_obj,
class Tc_uint=uint
>
class First:
public Pxx::First<
Types<Tc_obj,Tc_uint>
>
{
typedef Pxx::First<
Types<Tc_obj,Tc_uint>
>
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<Tc_obj,Tc_uint>
>
{
typedef Pxx::Second<
Types<Tc_obj,Tc_uint>
>
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<intfirst(100);
Second<intsecond(first);
--
Maksim A. Polyanin
http://grizlyk1.narod.ru/cpp_new

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

Mar 12 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.