Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
public class Student
{
public List<Student_detail>Student_details=new List<Student_detail>();
}
public class Student_detail
{
public string student_name{get;set;};
public string student_reg_no{get;set;};
}

The same thing, I used in C++. I am getting error.
The c++ code is below,
public class Student
{
public: List<Student_detail^>^Student_details=gcnew List<Student_detail^>();
}
public class student_detail
{
public: string student_name;
public:
			
string get(){return student_name;}
void set(string n){student_name=n;}

} 

I dont have much idea about c++. Help me.
Posted
Comments
KarstenK 11-Feb-14 4:45am    
what is the error?
Member 10500446 11-Feb-14 5:26am    
a handle to a non.managed class is not allowed,badly formed pure specifier(only='0'is allowed).these are the errors
Malli_S 11-Feb-14 5:30am    
The class names seem to be different or is it your typo?

'Student_detail' and 'student_detail'.
Member 10500446 11-Feb-14 5:40am    
While writing this question, I made a mistake. But in my code, it is correct. That is not the error. Thank u for the considerate reply...
KarstenK 11-Feb-14 5:51am    
what about "copy & paste" the compiler errors/message. So hard?

1 solution

What did you intend to do? Did you mean to a managed class or a native class?


What the List means? Did you mean the STL's std::list or the .NET's System::Collections::Generic::List?


What the string means? Did you mean the STL's std::string or the .NET's System::String?


I guess you intended to a managed class. So, maybe you intended to write something like this:


C++
public ref class Student_detail
{
private:
	System::String^ _student_name;
	System::String^ _student_reg_no;

public:
	property System::String^ student_name
	{
		System::String^ get() { return _student_name; }
		void set(System::String^ value) { _student_name = value; }			
	}

	property System::String^ student_reg_no
	{
		System::String^ get() { return _student_reg_no; }
		void set(System::String^ value) { _student_reg_no = value; }			
	}
 
};

public ref class Student
{
	public: 
		System::Collections::Generic::List<Student_detail^>^ Student_details;

		Student()
		{
			Student_details = gcnew System::Collections::Generic::List<Student_detail^>;
		}
};
 
Share this answer
 
Comments
Member 10500446 11-Feb-14 22:29pm    
Thank you so much...
Philippe Mori 14-Feb-14 18:23pm    
C++/CLI also has auto-implemented properties so the program could be written a bit simpler for read/write properties by writting: property System::String^ student_reg_no; and removing definition and associated private variable.

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



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