static method compile error when migrating from .NET 1.1 to 2.0
am 22.10.2007 18:28:00 von KevinMurphyRJLG
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?
Re: static method compile error when migrating from .NET 1.1 to 2.0
am 23.10.2007 15:19:10 von 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:oldSyntax command line option.
Re: static method compile error when migrating from .NET 1.1 to 2.
am 23.10.2007 18:12:01 von KevinMurphyRJLG
I hadn't been using "/clr:oldSyntax". 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'
"hpassant@gmail.com" wrote:
> 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:oldSyntax command line option.
>
>