Hi,
I have something similar to the following post, if not may be an extension http://www.c-sharpcorner.com/Forums/Thread/154204/how-to-pass-a-string-from-one-form-to-another.aspx
I have a namespace1 where i am instantiating the class in namespace2.
I have also included the header file and namespace2 i.e the class i have instantiated in namespace1 in 3 different places in namespace1 but what i need now i want to access properties of 2 different classes which are there in 3 header files where i have already included the namespace2 and the header file in as well.
This is just like including one header file1 in header file2 and vice versa which is not allowed which makes it a loop. Hence i tried forward declaration of the class in namespace1 which has access to the other two classes and properties and thought of using the same in namespace2 where i have not succeeded or need more support to work on.
Loading
VulpesPosted Feb 15, 2012, 5:07 PM
However, this sort of code is rather tortuous and I'd only use it if there's no practicable alternative.
Sam HobbsPosted Feb 17, 2012, 8:29 AM
There are still numerous syntax errors in the sample code. It helps to have sample code that compiles so I can do a compile of my modifications to ensure it works.
I am still not sure what you need. The following compiles and successfully executes. What else do you need the code to do that you are having problems with?
mainform.h
namespace namespace1{{public :mainform(void ){~mainform(void ){text.h
{{};}next.h
{{};}interface.h
{{{}{}};}Sample use
{}Karthik AgarwalPosted Feb 17, 2012, 12:29 AM
Sam HobbsPosted Feb 16, 2012, 3:22 AM
Your sample code helps. If you had done that in the beginning then that would have saved us all a lot of time. It is the type of thing I am trying to explain to you to do. That is a big part of what I am trying to say.
I still do not completely understand the problem.
I do not understand what "include text class in namespace2" means. A namespace is not #included so I do not know what you mean include in a namespace.
I also do not understand "access the properties of the both classes text and next". Where do you need to access those classes? Do you need to do that in the mainform class?
I think one barrier is that you need to think in terms of classes, not namespaces. Instead of trying to include a namespace I think you need to figure out how to use/access a class in another namespace.
Note that in the code you show above, the mainform class has a constructor and destructor for class1, not for mainform. I assume that is a mistake.
Karthik AgarwalPosted Feb 16, 2012, 2:25 AM
Sam HobbsPosted Feb 16, 2012, 2:18 AM
When I say ignore, one way is that when I spent a couple of hours working on some sample code for you and you did not say a single word about it.
Karthik AgarwalPosted Feb 16, 2012, 2:08 AM
//mainform.h
#include "interface.h"
#include "text.h"
#include "next.h"
using namespace2;
namespace namespace1
{
public ref class mainform : public System::Windows::Forms::Form
{
static text ^ text_setting = gcnew text;
static next ^ next_setting = gcnew next;
mainform(void)//EDITED
{
}
~mainform(void)//EDITED
{
}
}
}
//text.h
#include "interface.h"
using namespace2;
namespace namespace1
{
public ref class text
{
public:
String ^ text_name;//EDITED
String ^ sid_data;//EDITED
String ^ sample_string;//EDITED
}
}
//next.h
namespace namespace1
{
public ref class next
{
public:
String ^ _name;//EDITED
Font ^ _type;//EDITED
String ^ _aliaze;//EDITED
}
}
//interface.h
using namespace1;
namespace namespace2
{
public ref class 2
{
class2(void)
{
}
~class2(void)
{
}
}
}
now mainform has access to both text and next classes. I cant include text class in namespace2 as that has already included interface which makes it a loop. Now if i want to access the properties of the both classes text and next how can i do that?
//EDITED
I want to use class text and class next properties in namespace2 i.e in class2
I dont have any problem using them in mainform, but i am not sure how to use it in class2 (i.e in namespace2).
Also Note that i have changed the class1 to mainform, yup it was a mistake.
Also note that i have added some properties to classes text and next which i want to use in class2 (i.e in namespace2)
I hope everything is clear now. If you have anything else you can definitely ask me sam as you did now.
Karthik AgarwalPosted Feb 16, 2012, 12:40 AM
Sam HobbsPosted Feb 15, 2012, 7:30 PM
And here is the frustrating part. I will sincerely try to help but I will be ignored. That hurts.
Sam HobbsPosted Feb 15, 2012, 11:25 AM
I am different from Vulpes. I prefer to have a better understanding of a problem than Vulpes does.
It is very possible that the problem is related to some fundamental design issues. If so then I will say so. I understand that it might be too late to fix the fundamental design issues. Please allow me to explain problems like that when they apply. I will do the best I can to solve the problem in spite of design problems if necessary.
Regardless, before I can help you with this problem, you need to clarify things better.