namespaces and protected static members VC .NET bug?

I found bug when use namespaces in mfc application. When I wrote
DECLARE_MESSAGE_MAP/BEGIN_MESSAGE_MAP in base (CDialog-derived) class
A and in class B : public A (A and B in different namespaces). I
narrowed this problem to simple peace of code:

class A
{
protected:
	static int f;
	static int *p;
public:
	A()	{}
	~A() {}
};

int A::f = 1;
int *A::p = NULL;



namespace some {
	class A : public ::A
	{
		static int f;
		static int *p;

	public:
		A()	{}
		~A() {}
	};

	int A::f = 2;
	int *A::p = &::A::f; // this line produces error
}

This code does not work, VC compiller said: error C2248: 'A::f' :
cannot access protected member declared in class 'A'.

Then I remove namespace and rename second class A to B like this:

class B : public ::A
{
protected:
	static int f;
	static int *p;

public:
	B() {}
	~B() {}
};

int B::f = 2;
int *B::p = &A::f;


In this case everything work fine.

My compiller is:

Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 13.00.9466 for
80x86

Vith VC 6.0 first sample compiles fine.

Please do not suggest renaming classes,removing namespaces, use VC
6.0, etc.
0
oleg5147 (1)
9/6/2003 1:13:44 PM
vc.mfc 33608 articles. 0 followers. Follow

3 Replies
686 Views

Similar Articles

[PageSpeed] 3

What would you expect? ::A::p is protected.

Your ::B has access to ::A::p, because a derived class has access to the
protected members of the base class. Initialization of ::B::p is done with
the access checked as if in context of class B, this is why the
initialization can be compiled.

"Oleg Kolychev" <oleg@softservice.org> wrote in message
news:f7d7dac0.0309060513.bc72af9@posting.google.com...
> I found bug when use namespaces in mfc application. When I wrote
> DECLARE_MESSAGE_MAP/BEGIN_MESSAGE_MAP in base (CDialog-derived) class
> A and in class B : public A (A and B in different namespaces). I
> narrowed this problem to simple peace of code:
>
> class A
> {
> protected:
> static int f;
> static int *p;
> public:
> A() {}
> ~A() {}
> };
>
> int A::f = 1;
> int *A::p = NULL;
>
>
>
> namespace some {
> class A : public ::A
> {
> static int f;
> static int *p;
>
> public:
> A() {}
> ~A() {}
> };
>
> int A::f = 2;
> int *A::p = &::A::f; // this line produces error
> }
>
> This code does not work, VC compiller said: error C2248: 'A::f' :
> cannot access protected member declared in class 'A'.
>
> Then I remove namespace and rename second class A to B like this:
>
> class B : public ::A
> {
> protected:
> static int f;
> static int *p;
>
> public:
> B() {}
> ~B() {}
> };
>
> int B::f = 2;
> int *B::p = &A::f;
>
>
> In this case everything work fine.
>
> My compiller is:
>
> Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 13.00.9466 for
> 80x86
>
> Vith VC 6.0 first sample compiles fine.
>
> Please do not suggest renaming classes,removing namespaces, use VC
> 6.0, etc.


0
alegr (1131)
9/6/2003 3:15:48 PM
"Oleg Kolychev" <oleg@softservice.org> wrote in message
news:f7d7dac0.0309060513.bc72af9@posting.google.com...
> My compiller is:
>
> Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 13.00.9466 for
> 80x86

Oleg,

I'm no language lawyer, and I don't know which CL version is 13.00.9466
and which is 13.10.3077, but when I paste your code into the file
'SourceA.cpp' and compile it in VC7.1...

Compiling...
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 13.10.3077 for
80x86
Copyright (C) Microsoft Corporation 1984-2002. All rights reserved.
SourceA.cpp
SourceA - 0 error(s), 0 warning(s)

-- 
Jeff Partch [VC++ MVP]


0
jeffp (1712)
9/6/2003 3:15:49 PM
"Alexander Grigoriev" <alegr@earthlink.net> wrote in message
news:eB%23uDnIdDHA.1460@TK2MSFTNGP10.phx.gbl...
> What would you expect? ::A::p is protected.
>
> Your ::B has access to ::A::p, because a derived class has access to
the
> protected members of the base class. Initialization of ::B::p is done
with
> the access checked as if in context of class B, this is why the
> initialization can be compiled.

Comeau seems to compile it without errors as well...
-- 
Jeff Partch [VC++ MVP]


0
jeffp (1712)
9/6/2003 3:28:27 PM
Reply:

Similar Artilces:

.Net application architecture suggestion...
Hi, We are in the conceptual phase to create a relatively medium size enterprise business product application using Silver light 4.0, Entity Framework and WCF. 1. Is it adivceable to use Silverlight 4.0 for this enterprise business application development or should we go in for MVC.NET / ASP.NET? 2. We have planned to use REST based WCF service. How complex would it be to write the information back to the REST WCF service? I appreciate and welcome your advice / suggestion. If you need any further details do let me know, i will be happy to share. Thanks in advance. On 28-0...

Net Folders Message
We have a user that is sending a net folder message without her knowledge yet none of her folders are shared? Any ideas? Thanks Shona If the user is not using Net Folders then the easiest thing to do would be to disable Net Folders to ensure that this does not happen anymore. To disable Net Folders in Outlook 2000: 1. Open Outlook. 2. On the Tools menu, click Options, and then click Other. 3. Click Advanced Options, and then click Add-in Manager. 4. Clear the Net Folders check box. 5. Click OK twice. 6. Quit and start Outlook again. If you would like more information on Net Folders her...

Why is XMLSchema namespace so different than my custom namespace?
Below is a snippet that I'm sure is quite familiar to most ... <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" Here, I've given the XMLSchema namespace the prefix 'xsd', and with that, I can reference datatypes within the XMLSchema namespace ... i.e., xsd:string. That's great, but why can't I use that same notation, to reference dataypes in a homegrown schema ... WITHOUT doing an <import> or <include>? Is the XMLSchema (and the XMLSchema-instance) sort of "built-in" to XML tools, such that they don't need to go find th...

Cell Fromat Protection
I have a protected sheet that allows copy & pasting of unlocked cells, but I want to prevent the borders from getting changed while copy & pasting, is this possible? -- gmr7 Hi, Right click the cell you are pasting into and select "Paste Special" then select "All excpt borders" HTH -- Casey ------------------------------------------------------------------------ Casey's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=4545 View this thread: http://www.excelforum.com/showthread.php?threadid=498307 Is there any way to force th...

Copying Protected Worksheets
I have an excel spreadsheet that was password protected by an unknown user. Its an excellent tool and I'd like to adapt it for personal use. I've tried copying it to a blank spreadsheet and also "saving it as" another name in another folder. Neither method will allow me to make adjustments. There are numerous calculations I'd spend forever trying to create from scratch. Is there a way to do what I want? This works well: http://www.erlandsendata.no/english/downloads/tools.php --- Message posted from http://www.ExcelForum.com/ Or try this: Code: ---------------...

problem with form protection
I am using MS Word 2000. I have several documents that were created with an older version of word that have been saved and transferred to this computer. When I try to edit them they are protected. However, when I click the padlock on the toolbar to turn the protection off all of the information filled out in the form goes blank!Help! How do I edit the form without having to fill the entire thing out again?!? You will need to use a macro to re-apply the protection ActiveDocument.Protect wdAllowOnlyFormFields, NoReset -- Hope this helps, Doug Robbins - Word MVP Please re...

/forestprep /domainprep on member
Hi, what happens if you run /forestprep and /domainprep on the member server while logged on this server as domain/enterprise administrator? Can you rerun /forestprep and /domainprep on the DC that holds the schema master after you install Exchange Server 2003 in the domain? Everything seems to work fine but I am still curious if there is anything else that might make the problem later if /forestprep and /domainprep are not run on the DC. OS: Windows 2000 Domain: Windows 2000 Native Exchange 2000 upgraded to 2003 I would really appreciate any answer. Doug On Wed, 29 Jun 2005 17:42:06 +...

Mapping Fields using Crystal Reports in VS.NET 03
Hi, We're currently changing the location of the data source for a bunch of CR using VS.NET 03. For most stored procedures invoked by the reports, the change in data source goes without any change to the field mapping. We have a few stored procedures in reports that the Crystal plug-in is unable to map the fields from the current data source to the new one (SQL Server ODBC connections). The field names haven't changed, nor have their data types. It brings up the "Map Fields" dialog, but the upper-right quadrant, where the destination stored procedure is located, h...

Font for static dialog elements
Hello, I just need to change a default font (MS Sans Serif 8) used by VC++ for dialogs to something a little bigger like Arial 9. Although the IDE appears to allow for such modification when it comes to the STATIC TEXT (that's all I want !) and correctly displays a new font in the edit window, the executable is still stuck to the default font. When I open the resource file (.rc) outside of the VC editor, I can see that it does have relevant statements pointing that Arial 9 must be used in dialogs instead. In the effort to find the answer to my issue, I've gone through dozens ...

Bug report
Minor German localization has status "=D6ffnen" instead of "Offen". You guys need to get a *simple* way to report bugs online! Especially for something maturing (cough) as quickly as CRM! (first google result for [microsoft "report a bug"] is entitled "Mission: Impossible. Submitting a Bug Report to Microsoft") ...

Namespaces
Is there any documentations that will explain the Namespaces better or any help file? -- Matthew Heinrich Casino Queen Inc. Development Team ...

Distr lists in contain non GAL members?
Is it possible to create a Distribution list in the Global Address list that contains an external members address? So someone that does not have a mailbox on my exchange server but could be included on a distribution list? Thanks in advance, David P. Yes, just create a mail-enabled contact for that user (in Active Directory Users & Computers) and add it to the list. -- Neil Hobson Exchange MVP For Exchange news, links and tips, check: http://www.msexchange.co.uk "David P" <anonymous@discussions.microsoft.com> wrote in message news:1739e01c41d7d$813072d0$a601280a@...

Bugs in MS Money Plus (premium)?
Hello, I just (regrettably for the second time) upgraded MS Money, from MS Money 2007 to the current version. Though I cannot tell what the difference is (no visible difference in features), I thought perhaps this version would be at least 'less buggy'. However, from the start (login) I have seen numerous bugs. Does anyone have a list of known issues? Three that I encountered immediately: 1) logging in, I get an error message that my password is incorrect (even though it is), and upon second try it lets me in. 2) when clicking on the 'budget' icon in the toolbar, I g...

Protect formula against cut & paste
This is a multi-part message in MIME format. ------=_NextPart_000_00E3_01C5BCA2.5E761D10 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hello, I need to have a worksheet with the formula protected and some cells = unprotected to enter the values. The formulas uses the value in the = unprotected cell to make calculations. The problem is that if a user cut an unprotected cell and paste it in = another unprotected cell, Excell change the formula. I 'll try to explain with a simple example. I have all cells of a = worksheet protected ...

Protecting a document while still using it
I am trying to make a document where information can be typed into it, without the threat of losing any of my original form. The cells that you want to be able to type into can be unlocked by formatting the cell. Choose Format/Cell then click the Protection tab and uncheck the box marked "Locked" You can then protect your workesheet and only the unlocked cells will be available for change. "Jolene" <anonymous@discussions.microsoft.com> wrote in message news:D58D9A85-CFE4-4E24-8409-FD6D98A4CDE3@microsoft.com... > I am trying to make a document where information...

ANN: nxslt.exe (.NET XSLT Command Line Utility) version 1.5
Hello! I'm glad to announce version 1.5 of the nxslt.exe - .NET XSLT command line utility. What is nxslt ------------- nxslt is a feature-rich command line utility that allows to perform XSL Transformations (XSLT) using .NET Framework's XSLT implementation - System.Xml.Xsl.XslTransform class. nxslt is compatible with command line options, provided by Microsoft's MSXSL.EXE Command Line Transformation Utility. In addition, nxslt has some distinct advanced features, like support for XInclude and XPointer, embedded stylesheets, custom URI resolving, multiple result documents, custom ...

password protect individual worksheets
Can anybody help me. I am trying to password protect my worksheet 2 of 3 and I can not seem to find how this can be done. Any help will be grateful I'm familiar with protecting the Workbook, but not sure how to do a specific Worksheet. If someone knows, I'm sure they'll post a reply back. Sorry! You should be able to do this by selecting 'Tools', 'Protection' then choose protect worksheet. You can choose to protect it for certain things and apply a password. "Nick" wrote: > Can anybody help me. I am trying to password protect my worksheet 2 o...

Is it a bug?
ROUND(((2226-123.36-39.34-303)-1600)*0.05, 2) == 8.01 No. If you increase the DP to about 10 DP without the ROUND Function you will see the answer is 8.014999999999900 ROUND rounds it up to 8.01 Gord Dibben MS Excel MVP On Mon, 10 Dec 2007 08:45:26 +0800, "Cai Bing Lin" <half_worm{at} 163.com> wrote: >ROUND(((2226-123.36-39.34-303)-1600)*0.05, 2) == 8.01 > thank you . But when I use VBA. It will be 8.02? why? To 13 decimal places without the Round function (((2226-123.36-39.34-303)-1600)*0.05) is 8.0150000000000 "Gord Dibben" <gorddibbAT...

XmlSerializer and blank namespace
In 1.1, I could do this: XmlSerializer xs = new XmlSerializer(typeof(Doodad)); XmlSerializerNamespaces ns = new XmlSerializerNamespaces(); ns.add("", ""); xs.Serialize(writer, doodad, ns); and it produced: <doodad> .... </doodad> In 2.0, the same code produces: <doodad xmlns=""> .... </doodad> Any idea why and how to get rid of the blank namespace? ...

VS6 -> .NET migration, icon question
I have migrated a small MFC project from VS6 to .NET. One reason is that the end user wants me to use the 9 icon types standard for XP -- 16x16, 32x32, 48x48 at 4, 8, and 24 bit color depth. These are the icon types I see when I create an empty project however these types are not available after migration. For example, if I select "New Image Type..." I get a dialog to choose from with no icon type exceeding 8 bit color. If I select the "Custom..." button in this dialog, I am constrained by a combo box from creating any icon with greater than 8 bit color. How do I creat...

Xpath with namespaces
Hello Everyone, I am having an issue with xml and namespaces, at least I think it is namespaces. When I use namespaces, I cannot use SelectSingleNode / SelectNodes as they always return 0/Nothing respectively. Anyone have any thoughts? Thanks in advance VB.Net 2005 WinXP Sp2 Test code: Dim objXML As System.Xml.XmlDocument 'Test XML 1 ==> Always returns 0 objXML = New System.Xml.XmlDocument objXML.Load(Application.StartupPath & "\xmlfile1.xml") MsgBox(objXML.SelectNodes("top/middle").Count) 'Test XML 2 ==> Always re...

Protected Shared workbook with autofiltering
I want to have my workbook both protected and shared, whilst still leaving autofiltering turned on. The workbook runs fine without sharing it : at startup it calls a macro which: ..EnableAutoFilter = True ..Protect DrawingObjects:=True, _ contents:=True, Scenarios:=True, UserInterfaceOnly:=True for all relevant sheets. The important part is UserInterfaceOnly:=True, which if set allows autofiltering to (A) work, and (B) be controlled by code. Which is all great until I share the book - in a shared workbook you cannot call .Protect Now, you should simply be able to set your pro...

Excel Protection
I have set up an excel spread sheet and have used the data group an outline function to group rows together. .However when I choose sheet protection I am unable to use the grou and outline function. I also need to protect certain cells within the document, whil allowing users to edit pther ranges. Any suggestions gratefully recieve -- Message posted from http://www.ExcelForum.com Hi james Right click on the Sheet Name Tab and select "View Code" and paste in the code below Private Sub Worksheet_Activate() Me.Protect Password:="Secret", UserInterfaceOnly:=True ...

XML namespaces and XSD.exe
Oh boy i'm getting tangled in knots here. I have a schema which contains <xs:schema targetNamespace="http://Southend.Schemas.PAS/PASPatientDemographics.xsd" id="PASPatientDetails" xmlns:sh="http://Southend.Schemas.PAS/PASPatientDemographics.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"> now i used the xsd.exe and it now generates elements when I serilaize the class I get <RequestingPatient_ID xmlns="">D1234567890</RequestingPatient_ID> So each emlement contains xmlns=&qu...

protection problem
When I protect a work sheet, the tab key and the left/right arrows only work within the same row and will not go to the next cell in the next row. The Enter and up/down arrows do not work at all. To input data on the sheet, you have to keep using the mouse to go to the needed cell in each row. On a sedcond worksheet that is almost identical, the keys work correctly. Why does one sheet work and the next doesn't? ...