static method compile error when migrating from .NET 1.1 to 2.0

G

Guest

I have a managed c++ class with a number of static methods, all of which are
declared public. After switching from .NET 1.1 to 2.0 (Visual Studio 2003 to
VS 2005), I'm now getting compiler errors like:

error C2248: 'MyHelperClass::MyStaticMethod' : cannot access private member
in class MyHelperClass

I haven't made any code changes in MyHelperClass or the class that calls it.
Any ideas as to why this no longer compiles in VS 2005?
 
H

hpassant

Odd problem, you ought to post a few code snippets to show us the
problem. The only breaking change in the VS2005 compiler that might
be related is a change in the "friend" keyword. Also check that you
are now compiling with the /clr:blush:ldSyntax command line option.
 
G

Guest

I hadn't been using "/clr:blush:ldSyntax". I added it but I'm still getting the
errors. Here's an example of what I'm doing. Class/namespace/function names
have been changed.

Class with static methods:

namespace Utils
{
public __gc class ConversionUtils
{
private:
ConversionUtils(void);
~ConversionUtils(void);

public:
static int ConversionFunction1(int arg);
static int ConversionFunction2(int arg);
}
}

Calling class (in a different project):

int CallingClass::GetConvertedValue()
{
return Utils::ConversionUtils::ConversionFunction1(memberVariable);
}

This results in an error like:

error C2248: 'Utils::ConversionUtils::ConversionFunction1' : cannot access
private member declared in class 'Utils::ConversionUtils'
utils.dll : see declaration of 'Utils::ConversionUtils::ConversionFunction1'
utils.dll : see declaration of 'Utils::ConversionUtils'
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top