migrating from Visual Studio .NET 2003 to Visual Studio 2005

General C++ CLI (.net) programing

migrating from Visual Studio .NET 2003 to Visual Studio 2005

Postby mayag » Tue Apr 01, 2008 10:50 am

Hello all,

I'd very grateful for your help with compilation error I get after migrating from Visual Studio .NET 2003 to Visual Studio 2005.

class A is a managed class which contains pointer pPtr to unmanaged class as public member
class B is a managed class, derived from A.
In constructor of B there is an initialization of pPtr

after migrating from Visual Studio .NET 2003 to Visual Studio 2005 I get a compilation error:
cannot access a private member of class A (pPtr)

I'm using Old Syntax.

Thanks in advance,
Maya
mayag
 
Posts: 3
Joined: Tue Apr 01, 2008 10:40 am

Postby bernardos » Tue Apr 01, 2008 11:03 am

Hi Mayag,

Porting 2003 to 2005 is easyier if you adopt the new C++ CLI syntax :

-> managed pointers are with '^' (instead of '*') and other things.
-> change your A and B definitions to 'public ref class A' (to port it into new syntax)

-> Be sure your unmanaged object is after a 'public:' (it's 'private' by default).
-> Take a look at your new project (migration from 2003 to 2005): visual 2005 add a /Zi flag -> you have to remove it (Zi allow old syntax).

Bernardos
bernardos
 
Posts: 20
Joined: Fri Mar 30, 2007 9:33 pm

using Old Syntax

Postby mayag » Tue Apr 01, 2008 11:09 am

Hi,

thank you for your reply.
I need to use an old syntax...
mayag
 
Posts: 3
Joined: Tue Apr 01, 2008 10:40 am

Postby adminforum » Tue Apr 01, 2008 11:22 am

Hi,

We ported Marilou from old syntax to new syntax. Marilou contains C++ CLI and C++ native code. Using new syntax (for the CLI parts ) all is working fine. I think you may have to port it ...

You do not have to change anything in your C++ native code. Then changing to new CLI syntax will let you use Visual 2008 for example. Using old one you will always have problem in the future.

Admin
adminforum
Site Admin
 
Posts: 108
Joined: Wed Feb 07, 2007 10:10 am
Location: Montpellier - FR

Code Sample

Postby mayag » Tue Apr 01, 2008 6:53 pm

Here is a code sample that demonstrates the problem.
Please let me know if you have any other idea.

1) There is unmanaged class Singleton:

class Singleton {

public:

static Singleton* GetInstance();

private:

static Singleton * m_s;
...
};


2) managed base class A:


public class _gc A {

public:

Singleton * m_a;

};


3) managed derived class B :

public class _gc B : public A {
...

};


B::B() : A()
{
m_a = Singleton :: GetInstance(); // COMPILATION ERROR : cannot access private member in A
}
mayag
 
Posts: 3
Joined: Tue Apr 01, 2008 10:40 am

Postby adminforum » Wed Apr 02, 2008 7:06 am

Compile OK with Visual 2005 :

// singleton.cpp : main project file.

#include "stdafx.h"

using namespace System;

class Singleton
{
public:
static Singleton* GetInstance() {return(m_s); }

private:
//declare your variable existance
static Singleton * m_s;
};

//create static memory for this variable
Singleton * Singleton::m_s=0;

public ref class A
{
public:
Singleton * m_a;

A() {}
};

public ref class B: public A
{
public:
B();
};

B::B() : A()
{
m_a = Singleton :: GetInstance();
}


int main(array<System::String ^> ^args)
{
Console::WriteLine(L"Hello World");
return 0;
}
adminforum
Site Admin
 
Posts: 108
Joined: Wed Feb 07, 2007 10:10 am
Location: Montpellier - FR


Return to C++ CLI

Who is online

Users browsing this forum: No registered users and 0 guests

cron