473,382 Members | 1,349 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,382 software developers and data experts.

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

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? Here's a code example:

Class with static methods:
Expand|Select|Wrap|Line Numbers
  1. namespace Utils
  2. {
  3.     public __gc class ConversionUtils
  4.     {
  5.     private:
  6.         ConversionUtils(void);
  7.         ~ConversionUtils(void);
  8.  
  9.     public:
  10.         static int ConversionFunction1(int arg);
  11.         static int ConversionFunction2(int arg);
  12.     }
  13. }
  14.  
Calling class (in a different project):
Expand|Select|Wrap|Line Numbers
  1. int CallingClass::GetConvertedValue()
  2. {
  3.     return Utils::ConversionUtils::ConversionFunction1(memberVariable);
  4. }
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'
Oct 26 '07 #1
2 1380
kenobewan
4,871 Expert 4TB
It depends on whether the C++ class is managed or unmanaged code. If it is managed, you can set a normal assembly reference to it. If not, you need to use P/Invoke with the DLLImport or similar attribute. HTH.
Oct 26 '07 #2
Both the class with the static methods and the calling class are managed. The project with the calling class does have a reference to the dll that contains the class with the static methods.

It depends on whether the C++ class is managed or unmanaged code. If it is managed, you can set a normal assembly reference to it. If not, you need to use P/Invoke with the DLLImport or similar attribute. HTH.
Oct 29 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Roger Leigh | last post by:
The C++ book I have to hand (Liberty and Horvath, Teach yourself C++ for Linux in 21 Days--I know there are better) states that "static member functions cannot access any non-static member...
22
by: yellow1912 | last post by:
Hi, I'm very new to C#, in fact I dont know anything about it. Im having problem with its static variables. I used static variables alot in C++, but seem like C# doesnt allow it inside a function...
1
by: Jim Heavey | last post by:
I have a sealed public class which contains a couple of static public methods. I pass each of these methods, among other things, an instance of a class. When I compile this class and define each...
5
by: mast2as | last post by:
Hi guys Here's the class I try to compile (see below). By itself when I have a test.cc file for example that creates an object which is an instance of the class SpectralProfile, it compiles...
3
by: =?Utf-8?B?TkVXMi5ORVQ=?= | last post by:
I have a static event declared in a C++ ref class, that can then be handled in a VB app. I'm trying to expose the static event through the interface that the C++ ref class implements so the VB app...
9
by: Steve Richter | last post by:
in a generic class, can I code the class so that I can call a static method of the generic class T? In the ConvertFrom method of the generic TypeConvert class I want to write, I have a call to...
2
by: =?Utf-8?B?S2V2aW5NdXJwaHlSSkxH?= | last post by:
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...
4
by: Jon Skeet [C# MVP] | last post by:
On Aug 11, 5:11 am, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com> wrote: Exactly. My favourite example is Thread.Sleep. Suppose this code were valid (its equivalent in Java is, for example): ...
4
by: HxRLxY | last post by:
I am having a compile-time problem with a simple program I am writing. When I attempt to compile, I get the error "non-static variable this cannot be referenced from a static context". The error...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.