473,320 Members | 1,900 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,320 software developers and data experts.

Why doesn't this compile?

The following fails under VC8 Beta2:
namespace A {

// forward decl.
template <typename Type, typename TypeX>
bool foo(const Type&, const TypeX&);

} // namespace A
namespace A {
namespace B {

template <typename Type>
struct S
{
template <typename Type, typename TypeX>
friend bool ::A::foo(const Type&, const TypeX&); // error C2888

protected:
template <typename TypeX>
static bool bar(const Type& a, const TypeX& b)
{
return a == b;
}
};

} // namespace B

template <typename Type, typename TypeX>
bool foo(const Type& a, const TypeX& b)
{
return B::S<Type>::bar(a, b);
}

} // namespace A
int main()
{
}

The error message is:

..\Test.cpp(114) : error C2888: 'bool A::foo(const Type &,const TypeX
&)' : symbol cannot be defined within namespace 'B'
..\Test.cpp(122) : see reference to class template instantiation
'A::B::S<Type>' being compiled

Can someone explain why?
Thanks,

- NK

Jul 23 '05 #1
5 4429
"narechk" <na*****@gmail.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com
The following fails under VC8 Beta2:
namespace A {

// forward decl.
template <typename Type, typename TypeX>
bool foo(const Type&, const TypeX&);

} // namespace A
namespace A {
namespace B {

template <typename Type>
struct S
{
template <typename Type, typename TypeX>
friend bool ::A::foo(const Type&, const TypeX&); // error C2888

protected:
template <typename TypeX>
static bool bar(const Type& a, const TypeX& b)
{
return a == b;
}
};

} // namespace B

template <typename Type, typename TypeX>
bool foo(const Type& a, const TypeX& b)
{
return B::S<Type>::bar(a, b);
}

} // namespace A
int main()
{
}

The error message is:

.\Test.cpp(114) : error C2888: 'bool A::foo(const Type &,const TypeX
&)' : symbol cannot be defined within namespace 'B'
.\Test.cpp(122) : see reference to class template instantiation
'A::B::S<Type>' being compiled

Can someone explain why?


There appears to be a bug:

http://lab.msdn.microsoft.com/produc...2-d67ccd795fc7
--
John Carson

Jul 23 '05 #2
* narechk:


Compiles fine with gcc 3.4.2.

Also compiles fine with Comeau Online when the struct S template parameter
is renamed to e.g. "LType" (and correspondingly for S::bar).

Otherwise Comeau detects a "template parameter "Type" may not be redeclared
in this scope", but the fix for Comeau doesn't help with Visual C++ 7.1 (I
don't have the 8.0 beta 2).

--
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?
Jul 23 '05 #3
Right. This is not good. Does anyone know if there is a workaround?

Thanks,

- NK

Jul 23 '05 #4
* narechk:
Right. This is not good. Does anyone know if there is a workaround?


E.g. place foo in namespace B and just a forwarding foo in namespace A.

--
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?
Jul 23 '05 #5
Everyone thanks for your help. This is a real bloody showstopper. Will
have to redesign.

- NK

Jul 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: James Thurley | last post by:
I'm trying to dynamically compile assemblies and cache them to disk, which seems to work fine. When the data I'm compiling from changes, I want to re-generate the assembly and use the new version....
4
by: Fernando Cuenca | last post by:
Hi, I'm trying to explicitly instantiate a template function using the following syntax: obj.template_func<type>(params); It compiles OK when used from a regular function, but it doesn't...
12
by: Rhino | last post by:
I am having an odd problem: the sqlj command on my system doesn't work. I am running DB2 (LUW) V8 (FP8) on WinXP. I haven't done an sqlj program since Version 6 of DB2 (LUW) so I checked the...
3
by: Karl Irvin | last post by:
When I click Debug>Compile, my modules seem to comple OK but the Compile menu choice doesn't gray out (to indicate compiling is not needed). The IsCompiles returns false, no matter how many times...
149
by: Christopher Benson-Manica | last post by:
(Followups set to comp.std.c. Apologies if the crosspost is unwelcome.) strchr() is to strrchr() as strstr() is to strrstr(), but strrstr() isn't part of the standard. Why not? --...
1
by: rvan | last post by:
Hi, I am trying to port one of my older MFC APP created in VC 6.0 to VC 7.0. Right away after starting the compile process, I get following errors and compilation stops. "d:\Microsoft .NET...
4
by: Eric Lilja | last post by:
Is this an invalid program? Doesn't compile on my system: #include <cstdio> class Why { enum TArch {LITTLE_ENDIAN, BIG_ENDIAN, NON_IEEE}; TArch Architecture; }; int
10
by: Sourcerer | last post by:
I wrote this very simple code in .NET VC++. I compiled it on my system, and tried to run it on my friend's computer (he doesn't have the compiler). We both have Windows XP Professional. I have .NET...
13
by: hn.ft.pris | last post by:
Hi: I have the following simple program: #include<iostream> using namespace std; int main(int argc, char* argv){ const double L = 1.234; const int T = static_cast<const int>(L); int arr;
35
by: mwelsh1118 | last post by:
Why doesn't C# allow incremental compilation like Java? Specifically, in Java I can compile single .java files in isolation. The resulting individual .class files can be grouped into .jar files....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.