473,385 Members | 2,069 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Two equal examples, but can not compile second

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
3 1868
* 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
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

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: lmckaha | last post by:
Hi, Mysql version: 3.23.49 Solaris version: 2.7 gcc compiler version: 2.95.2 Python : 2.2.2 I'm evaluating the C and C++ API to decide which one to bye but I have many troubles.
23
by: Gunnar G | last post by:
Hello. I'm trying to write a class for integers with a very large number of digits and it seemed to work until I tried to add three numbers. d=a+b+c; works fine (hasn't checked the result yet)...
1
by: sam++ | last post by:
Hi, I cd into examples/DLL/ and type "make", it failed to compile the example. The error is: # make make - -f DLL_Today.bor all make: don't know how to make all. Stop *** Error code 2 ...
1
by: Andy Jeffries | last post by:
Hi all, I want to have two elements have an equal height, with that height being the larger of the two (with dynamic content). In one case they are just side by side so I want them to look even...
1
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - Why does 1+1 equal 11? or How do I convert a string to a number?...
6
by: Internet User | last post by:
Can anyone point me to examples of commercial software packages (i.e. sold through VARs or retail channels) that were programmed in VB.net? Thanks in advance.
14
by: serge calderara | last post by:
Dear all, What is the proper way to check if two object are equal ? I do not mean equal on Object type only but also object value's thnaks for help regards serge
1
by: Doug Arnott | last post by:
http://www.cs.rutgers.edu/~pxk/rutgers/notes/pdf/Cstyle.pdf has an example at the end of the document of an example of an alternative implementation of interest to me. In this example, the...
11
by: Bernard.Mangay | last post by:
The remainder is non zero due to rounding errors. How can I remove the rounding errors?
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.