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

BUG: C2352 with template base class (VS .NET 2003)

Hi folks,

I found a bug in VS .NET 2003. When compiling the following code with FAIL defined
I get an error C2352
'B<T>::g::B<T>::g': Unzulässiger Aufruf einer nicht statischen Memberfunktion
with
[
T=COuter::Element *
]
and
[
T=COuter::Element *
]

Since g is not static I believe this is a compiler error. It works with the two
workarounds presented for f and f2. The error does not occur if FAIL is not
defined.

template <class T> class B {
public:
virtual bool f() const { return true; }
virtual bool g() const { return true; }
};

#undef FAIL
#define FAIL

#ifdef FAIL
class COuter
{
#endif
class Element {
};
typedef B<Element *> B_2;
class CInner : public B_2
{
// These work
virtual bool f () const { return B<Element *>::f(); }
virtual bool f2() const { return __super::f(); }
// This fails
virtual bool g () const { return B_2::g(); }
};
#ifdef FAIL
};
#endif

Kind regards,
Werner Henze

Nov 16 '05 #1
4 1952

"Werner Henze" <w.*****@avm.de> skrev i meddelandet
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hi folks,

I found a bug in VS .NET 2003. When compiling the following code with FAIL defined I get an error C2352
'B<T>::g::B<T>::g': Unzulässiger Aufruf einer nicht statischen Memberfunktion with
[
T=COuter::Element *
]
and
[
T=COuter::Element *
]

Since g is not static I believe this is a compiler error. It works with the two workarounds presented for f and f2. The error does not occur if FAIL is not defined.

template <class T> class B {
public:
virtual bool f() const { return true; }
virtual bool g() const { return true; }
};

#undef FAIL
#define FAIL

#ifdef FAIL
class COuter
{
#endif
class Element {
};
typedef B<Element *> B_2;
You cannot instantiate the template B with a local class. If you move
these three lines to global scope, it works.

That is what happens when you remove COuter!

class CInner : public B_2
{
// These work
virtual bool f () const { return B<Element *>::f(); }
virtual bool f2() const { return __super::f(); }
// This fails
virtual bool g () const { return B_2::g(); }
};
#ifdef FAIL
};
#endif

Kind regards,
Werner Henze

Bo Persson
bo**@telia.com


Nov 16 '05 #2
> > };
typedef B<Element *> B_2;
You cannot instantiate the template B with a local class. If you

move these three lines to global scope, it works.

I don't think that this is entirely correct. B is instantiated on
Element*
and not on Element. Furthermore, Element is not a local class.
Classes in functions cannot be used as template arguments. This
is not true for nested classes.

IMHO the code demonstrates a compiler bug.

-hg

Nov 16 '05 #3
OK, let's assume your statement is correct. Then why don't I get an error on
typedef B<Element *> B_2;
and on
class CInner : public B_2
and on
virtual bool f () const { return B<Element *>::f(); }
?
Either way I think there is a bug in the VC++ compiler.

Kind regards,
Werner Henze
Nov 16 '05 #4
Hi Werner,
Thank you for your report. It does look like a compiler bug. The latest
internal build of the compiler can compile your code without any issues.

--
Keiji Oenoki
Visual C++ Team
This posting is provided AS IS with no warranties, and confers no rights.
--------------------
From: "Werner Henze" <w.*****@avm.de>
Subject: BUG: C2352 with template base class (VS .NET 2003)
Date: Mon, 14 Jul 2003 14:06:48 +0200
Lines: 49
MIME-Version: 1.0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 8bit
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <#a**************@TK2MSFTNGP10.phx.gbl>
Newsgroups: microsoft.public.dotnet.languages.vc
NNTP-Posting-Host: 194.175.125.253
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP10.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vc:26107
X-Tomcat-NG: microsoft.public.dotnet.languages.vc

Hi folks,

I found a bug in VS .NET 2003. When compiling the following code with FAIL defined I get an error C2352
'B<T>::g::B<T>::g': Unzulässiger Aufruf einer nicht statischen Memberfunktion with
[
T=COuter::Element *
]
and
[
T=COuter::Element *
]

Since g is not static I believe this is a compiler error. It works with the two workarounds presented for f and f2. The error does not occur if FAIL is not defined.

template <class T> class B {
public:
virtual bool f() const { return true; }
virtual bool g() const { return true; }
};

#undef FAIL
#define FAIL

#ifdef FAIL
class COuter
{
#endif
class Element {
};
typedef B<Element *> B_2;
class CInner : public B_2
{
// These work
virtual bool f () const { return B<Element *>::f(); }
virtual bool f2() const { return __super::f(); }
// This fails
virtual bool g () const { return B_2::g(); }
};
#ifdef FAIL
};
#endif

Kind regards,
Werner Henze

Nov 16 '05 #5

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

Similar topics

4
by: Matt Graham | last post by:
ok, I have 2 classes roughly like these 2: class A; // various data classes to be used in D class B { public: void x() { y() } protected: virtual void y(); };
25
by: John Harrison | last post by:
This code fails to compile on Comeau C++ and VC++ 7.1 (with language extensions disabled) template <class T> struct B { T b; }; template <class T>
1
by: Vikas | last post by:
I have a template class called Base with child classes called Child1 and Child2 as follows: template <typename T> class Base { … }; class Child1 : Base<Concrete1>
4
by: michael.alexeev | last post by:
Hi all. Consider the following code fragment: #include <string> struct Base{ virtual ~Base() {} }; template <typename T> struct Derived : public Base {}; Base* Create (int param) { switch...
2
by: vilarneto | last post by:
Hello everyone, I'm facing a particular situation about template class derivation. The subject is old -- deriving a non-template class from a template base class -- but my problem is that the...
6
by: chris.kemmerer | last post by:
I am having a problem with templates and I hope someone here can help. I am writing a library that accepts data packets, parses them and saves the information for later use. One member of the...
1
by: John Femiani | last post by:
Hi all, I have come across a problem using g++. The example below illustrates the issue: -------------------------------------------------------- #include <iostream> template<class T>...
5
by: Harinezumi | last post by:
Hello, I need help with the design of a serialization template base class. The idea is that any class derived from this template base class would only need to implement the input and output...
2
by: henrik.jacobsson | last post by:
Dear C++ gurus out there, Can anyone please tell me why A<string>::f(const pair<int,T>& _p) is not found in B<string>? (compiler version: g++ (GCC) 4.1.3 20070929 (prerelease) (Ubuntu...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.