niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
·  nixdoc.net ·  man pages ·  Linux HOWTOs ·  FreeBSD Tips ·  Forums
navigation Forum index » Programming » C++
template type problem in msvc. and more
Post new topic   Reply to topic Page 1 of 1 [2 Posts] View previous topic :: View next topic
Author Message
Bogdan Sintoma
*nix forums beginner


Joined: 14 Mar 2005
Posts: 10

PostPosted: Wed Feb 02, 2005 12:44 pm    Post subject: Re: template type problem in msvc. and more Reply with quote

icedac wrote:
Quote:
I have some questions about template and c++ itself.


/////////////////////////////////////////////////////////////////////////
q1) see follow c++ code, and compile. it's works only IntelC++8.1 but
VC71.
Do you know why? Which compiler's activity is C++STANDARD? And I
wanna
be
feed back some explain. :)




//-----------------------------------------------------------------------
//
// COMPILER_TEST!,
//
// a) VC71 fail to compile
// b) IC81 OK
//

//-----------------------------------------------------------------------
template < typename MY_TYPE_
class TestClass1
{
public:
typedef int TEST_TYPE;
};

template < typename MY_TYPE_
class TestClass2
{
public:
typedef MY_TYPE_ MY_TYPE;
typedef TestClass1<MY_TYPE> TEST_CLASS1;
typedef TestClass2<MY_TYPE> TEST_CLASS2;
typedef typename TEST_CLASS1::TEST_TYPE TEST_TYPE1;


//typename TestClass2<MY_TYPE_>:: // this make msvc happy, but I
dont
know why!
TEST_TYPE1 TestMethod1();
I think it is a problem in VC. IMHO, those definitions are equivalent.


Quote:

//
// consequently,
// a) typename TestClass2<MY_TYPE_>::TEST_TYPE1
// and
// b) TEST_TYPE1
//
// is different type! why? its the same type!
//
// i think its result due to the "typename"
//
Don't know. Maybe you should post those questions also in a VC related

newsgroup.

Quote:

void TestMethod2( TEST_TYPE1 a );
};

/* this will emit error in MSVC */
template < typename MY_TYPE_
typename TestClass2<MY_TYPE_>::TEST_TYPE1 /* return type; return type
can not use types in TestClass2
it have to specify TestClass2 scope to compile*/
TestClass2<MY_TYPE_>::TestMethod1()
{
printf( "typename TestClass2<MY_TYPE_>::TEST_TYPE1
TestClass2<MY_TYPE_>::TestMethod1() - called.\r\n" );
return 0;
}

/* this is ok */
template < typename MY_TYPE_
void
TestClass2<MY_TYPE_>::TestMethod2(
//typename TestClass2<MY_TYPE_>:: //this var is on scope of
TestClass2, it can use types in TestClass2
TEST_TYPE1 a
)
{
return 0;
}

Hm, it doesn't look ok. The method has void type as return type, but

you return 0. I know that VC is silent about that, but it should say
something, at least a warning.

Quote:

void test_2()
{
TestClass2<int> a;
a.TestMethod1();
}
//---------END_OF_CODE


/////////////////////////////////////////////////////////////////////////
q2)
code:
//-- start of code
class TestCalss3
{
public:
typedef int TEST_TYPE3;
TEST_TYPE3 TestMethod3( TEST_TYPE3 a );
};

inline
TestCalss3::TEST_TYPE3 TestCalss3::TestMethod3( TEST_TYPE3 a )
{
return 1;
}
Here I don't know how real 'a' type is deduced (there is no such type

in global namespace). Well, I'll search a little Smile. Comeau online also
compile fine this method implementation.

Quote:
//-- end of code

Why c++ standard make difference between 'RETURN type' and 'ARGUMENT
type'?
I think 'new code1' or 'new code2' is looks better. Or I omit some
important point(s) about c++ design or compiler design?

//-- new code1
inline
TEST_TYPE3 TestCalss3::TestMethod3( TEST_TYPE3 a )
{
return 1;
}
Not correct, as I said there isn't such a type in the global namespace

(equivalent with TestCalss3::TEST_TYPE3, eg. typedef
TestCalss3::TEST_TYPE3 TEST_TYPE3).

Quote:
//-- new code2
inline
TestCalss3::TEST_TYPE3 TestCalss3::TestMethod3(
TestCalss3::TEST_TYPE3
a )
{
return 1;
}
//--

This is ok Smile.

..

..
Best regards,
Bogdan Sintoma
Back to top
icedac
*nix forums beginner


Joined: 02 Feb 2005
Posts: 1

PostPosted: Wed Feb 02, 2005 5:37 am    Post subject: template type problem in msvc. and more Reply with quote

I have some questions about template and c++ itself.

/////////////////////////////////////////////////////////////////////////
q1) see follow c++ code, and compile. it's works only IntelC++8.1 but
VC71.
Do you know why? Which compiler's activity is C++STANDARD? And I wanna
be
feed back some explain. Smile



//-----------------------------------------------------------------------
//
// COMPILER_TEST!,
//
// a) VC71 fail to compile
// b) IC81 OK
//
//-----------------------------------------------------------------------
template < typename MY_TYPE_ >
class TestClass1
{
public:
typedef int TEST_TYPE;
};

template < typename MY_TYPE_ >
class TestClass2
{
public:
typedef MY_TYPE_ MY_TYPE;
typedef TestClass1<MY_TYPE> TEST_CLASS1;
typedef TestClass2<MY_TYPE> TEST_CLASS2;
typedef typename TEST_CLASS1::TEST_TYPE TEST_TYPE1;


//typename TestClass2<MY_TYPE_>:: // this make msvc happy, but I dont
know why!
TEST_TYPE1 TestMethod1();

//
// consequently,
// a) typename TestClass2<MY_TYPE_>::TEST_TYPE1
// and
// b) TEST_TYPE1
//
// is different type! why? its the same type!
//
// i think its result due to the "typename"
//

void TestMethod2( TEST_TYPE1 a );
};

/* this will emit error in MSVC */
template < typename MY_TYPE_ >
typename TestClass2<MY_TYPE_>::TEST_TYPE1 /* return type; return type
can not use types in TestClass2
it have to specify TestClass2 scope to compile*/
TestClass2<MY_TYPE_>::TestMethod1()
{
printf( "typename TestClass2<MY_TYPE_>::TEST_TYPE1
TestClass2<MY_TYPE_>::TestMethod1() - called.\r\n" );
return 0;
}

/* this is ok */
template < typename MY_TYPE_ >
void
TestClass2<MY_TYPE_>::TestMethod2(
//typename TestClass2<MY_TYPE_>:: //this var is on scope of
TestClass2, it can use types in TestClass2
TEST_TYPE1 a
)
{
return 0;
}


void test_2()
{
TestClass2<int> a;
a.TestMethod1();
}
//---------END_OF_CODE

/////////////////////////////////////////////////////////////////////////
q2)
code:
//-- start of code
class TestCalss3
{
public:
typedef int TEST_TYPE3;
TEST_TYPE3 TestMethod3( TEST_TYPE3 a );
};

inline
TestCalss3::TEST_TYPE3 TestCalss3::TestMethod3( TEST_TYPE3 a )
{
return 1;
}
//-- end of code

Why c++ standard make difference between 'RETURN type' and 'ARGUMENT
type'?
I think 'new code1' or 'new code2' is looks better. Or I omit some
important point(s) about c++ design or compiler design?

//-- new code1
inline
TEST_TYPE3 TestCalss3::TestMethod3( TEST_TYPE3 a )
{
return 1;
}
//-- new code2
inline
TestCalss3::TEST_TYPE3 TestCalss3::TestMethod3( TestCalss3::TEST_TYPE3
a )
{
return 1;
}
//--



/////////////////////////////////////////////////////////////////////////
I'll expect good reply. Thank you in advance.
ps excuse my BAD english Smile I'm not native writer :0
Back to top
Google

Back to top
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [2 Posts] View previous topic :: View next topic
The time now is Thu Jan 08, 2009 7:46 pm | All times are GMT
navigation Forum index » Programming » C++
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts Unknown in header problem -SOLVED- Light Speed Postfix 0 Thu Jul 03, 2008 10:40 am
No new posts problem with sending mail nuxia Postfix 0 Mon Apr 21, 2008 3:58 am
No new posts Postfix 2.3.8 Virtual problem Blotto Postfix 0 Fri Apr 04, 2008 6:11 am
No new posts Postfix sending problem for local domain remote email monkey_magix Postfix 0 Mon Sep 10, 2007 10:17 am
No new posts bounce problem murkis Postfix 0 Sun Oct 08, 2006 3:45 pm

Debt Consolidation | Remortgages | Loans | Debt Consolidation | Download Anime
Copyright © 2004-2005 DeniX Solutions SRL
 
Other DeniX Solutions sites: Unix/Linux blog |  electronics forum |  medicine forum |  science forum | 
Privacy Policy


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.3956s ][ Queries: 20 (0.2809s) ][ GZIP on - Debug on ]