473,324 Members | 2,246 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,324 software developers and data experts.

compiler bug?

The following code causes an error when compiled with VC++ 2005
namespace x
{
template <class Tclass X;
namespace y
{
class Y
{
template <class T>
friend class X;
};
}
}

The error is at the friend declaration

error C2888: 'x::X' : symbol cannot be defined within namespace 'y'

The same code compiles with g++ or with VC++ 2005 if you remove the
namespace x.

Is this a compiler bug? Are there any known work arounds?

Thanks,
John
Feb 4 '07 #1
5 1540
On Sun, 04 Feb 2007 16:50:58 GMT, John Harrison <jo*************@hotmail.com>
wrote:
>The following code causes an error when compiled with VC++ 2005
namespace x
{
template <class Tclass X;
namespace y
{
class Y
{
template <class T>
friend class X;
};
}
}

The error is at the friend declaration

error C2888: 'x::X' : symbol cannot be defined within namespace 'y'

The same code compiles with g++ or with VC++ 2005 if you remove the
namespace x.

Is this a compiler bug? Are there any known work arounds?
It appears to be a compiler bug. The code is perfectly legal as far as I can
tell.

-dr
Feb 5 '07 #2
On Feb 4, 5:50 pm, John Harrison <john_androni...@hotmail.comwrote:
The following code causes an error when compiled with VC++ 2005

namespace x
{
template <class Tclass X;
namespace y
{
class Y
{
template <class T>
friend class X;
};
}

}

The error is at the friend declaration

error C2888: 'x::X' : symbol cannot be defined within namespace 'y'

The same code compiles with g++ or with VC++ 2005 if you remove the
namespace x.
The code with the "namespace x" compiles without errors (or warnings)
with g++ versions 3.3, 4.0 and 4.1 (I just tried it on a linux amd 64
system).
What version of g++ were you using that gives the problem?

Feb 5 '07 #3
What version of g++ were you using that gives the problem?

I was using VC++ 2005.

Feb 5 '07 #4
Try the following and do not break your head about "fast compiled friends":

namespace x
{
template <class Tclass X;

namespace y
{

class Y
{
int i;
int k;

public:
class Tfriend
{
Y &y;

public:
int& i(){return y.i;}
const int& i()const {return y.i;}

int& k(){return y.k;}
const int& k()const {return y.k;}

Tfriend(const Y& p):y(const_cast<Y&>(p)){}
};
};

//namespace y
}

template <class T>
class X
{
public:
inline int get(y::Y& p)
{
const y::Y::Tfriend fr(p); return fr.i();
}
};

void test()
{
X<char x;
y::Y y;

x.get(y);
}

//namespace x
}

--
Maksim A. Polyanin

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

Feb 5 '07 #5

"John Harrison" <jo*************@hotmail.comwrote in message
news:S9******************@newsfe5-win.ntli.net...
The following code causes an error when compiled with VC++ 2005
namespace x
{
template <class Tclass X;
namespace y
{
class Y
{
template <class T>
friend class X;
};
}
}

The error is at the friend declaration

error C2888: 'x::X' : symbol cannot be defined within namespace 'y'

The same code compiles with g++ or with VC++ 2005 if you remove the
namespace x.

Is this a compiler bug? Are there any known work arounds?
Yes, it's a known bug. Supposed to be fixed in an update by now, I thought.
Check Microsoft for updates.
-Howard
Feb 7 '07 #6

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

Similar topics

2
by: Jeff Epler | last post by:
Hello. Recently, Generator Comprehensions were mentioned again on python-list. I have written an implementation for the compiler module. To try it out, however, you must be able to rebuild...
13
by: Bryan Parkoff | last post by:
You may notice that switch (...) is much faster than function that can gain a big improved performance because it only use JMP instruction however function is required to use CALL, PUSH, and POP...
10
by: Bjorn | last post by:
I'm using interfaces in C++ by declaring classes with only pure virtual methods. If then someone wants to implement the interface they needs to inherit from the class. If the implementing class...
7
by: Tao Wang | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, I saw cuj's conformance roundup, but the result is quite old. I think many people like me want to know newer c++ standard conformance test...
14
by: joshc | last post by:
I'm writing some C to be used in an embedded environment and the code needs to be optimized. I have a question about optimizing compilers in general. I'm using GCC for the workstation and Diab...
16
by: pj | last post by:
(Was originally, probably wrongly, posted to the vc subgroup.) (This doesn't appear to be a c# problem, but a problem with a bug in the Visual Studio c# compiler, but, any help will be welcome...)...
0
by: rollasoc | last post by:
Hi, I seem to be getting a compiler error Internal Compiler Error (0xc0000005 at address 535DB439): likely culprit is 'BIND'. An internal error has occurred in the compiler. To work around...
3
by: Mark Rockman | last post by:
------ Build started: Project: USDAver2, Configuration: Debug .NET ------ Preparing resources... Updating references... Performing main compilation... error CS0583: Internal Compiler Error...
6
by: toton | last post by:
Hi, Anyone have a link to comparative study of different C++ compilers and how much they conform to C++ language standard? Most of the big platforms I know have GCC which well supports C++...
41
by: Miroslaw Makowiecki | last post by:
Where can I download Comeau compiler as a trial version? Thanks in advice.
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
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
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...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.