Click here to Skip to main content
15,892,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have following classes
following code is defined in nurse.h
#pragma once
#include "shift.h"
namespace Manage{
	private ref class nurse
	{
List<shift^> ^_daysServedlst;//here comes the error that shift is not defined in Manage Though it is available in auto complete list
...
};
}

the following code block is defined in shift.h
#pragma once
#include "nurse.h"
namespace Manage
{
	using namespace System;
	using namespace System ::Collections ::Generic ;
	
 private ref class shift : IComparable
	{
};

the problem is the compilation error occurs when I try to make an object of shift class in any function of nurse class
Error message error C2039: 'shift' : is not a member of 'Manage'
Please help
Posted
Updated 21-Jun-11 8:29am
v3
Comments
Albert Holguin 21-Jun-11 14:14pm    
So this looks like C#, not C++... tag accordingly...
Sergey Alexandrovich Kryukov 21-Jun-11 14:31pm    
No, not C#, this is C++/CLI (which is not C++).
--SA
Albert Holguin 21-Jun-11 15:15pm    
that's why I didn't retag myself... :)
J imran 21-Jun-11 14:18pm    
it is c++
Sergey Alexandrovich Kryukov 21-Jun-11 14:27pm    
No! This is C++/CLI, which is not C++, strictly speaking. Tag it!
--SA

1 solution

Stop cross-include of your header files and you will be fine. Put the declarations in one header file, for example.

You also need forward class declaration. For example:

C++
ref class BBB;
public ref class AAA {
    BBB^ bbb;
    //...
};

public ref class BBB {
    AAA^ aaa;
    //...
};


It won't be possible if you used not class references by the instances in by-value semantic, by obvious reasons: instantiation would cause infinite construction due to infinite constructor recursion.

—SA
 
Share this answer
 
v3
Comments
J imran 21-Jun-11 14:43pm    
thank you. It works.
Sergey Alexandrovich Kryukov 21-Jun-11 14:52pm    
You're welcome.
Thanks for accepting the solution, but it was incomplete. The root of the problem is the lack of forward declaration. Solution updated.
Good luck, call again.
--SA
J imran 21-Jun-11 15:38pm    
bool DayExists(shift ^_shift)
{
bool reply = false;
for (int i = 0; i < _daysServedlst->Count; i++)
{
if (_daysServedlst[i]->ShiftInfo->DayNumber == _shift->ShiftInfo->DayNumber)
{
reply=true;
break;
}
}
return reply;
}
I have done what you said. I am facing strange problems. this function is defined in nurse class. I have included the declarations in a single Manage.h file. here comes the error Shift does not exist in Manage namespace. Though making an object of shift in nurse class works fine. I am not sure why in if statement there comes error.
Mark Salsbery 21-Jun-11 15:56pm    
You state "Shift does not exist in Manage namespace." but nowhere do you use "Shift" in that code. C# and C++ are case-sensitive and require names to be exact, not just close. ;) So what aren't you showing us?
J imran 21-Jun-11 16:01pm    
is there any free tool to convert c# to c++

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900