Can someone please post a short example of how to define a class of some longs and chars that LinkedList(T) will accept?
I know that on this page http://msdn.microsof...y/he2s3bh7.aspx there is a great write up about the LinkedList Class. Unfortunately, it only shows how to use the LinkedList class with a String.
I have about 9 hours in on trying to get it to compile in Visual C++ 2008 using either a struct or a very simple class. I am interfacing with a system that gives me 4 longs and one char[100] as a struct. As these arrive, I need to put them in a linkedlist and would like to use the built in class.
I have tried so many hundreds of ways to get this to work at this point, that I would prefer not to post my non-working spaghetti code. I am a long time multi-platform C programmer but am very new to .Net so please be explicit if possible.
Many thanks in advance,
Kyle
C++ .Net LinkedList(T) Non-String Example Needed
Page 1 of 14 Replies - 1229 Views - Last Post: 07 March 2010 - 09:18 AM
Replies To: C++ .Net LinkedList(T) Non-String Example Needed
#2
Re: C++ .Net LinkedList(T) Non-String Example Needed
Posted 07 March 2010 - 07:55 AM
Hi Kyle....
Sorry, but we won't do your homework for you. Please re-read our rules/policies:
Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.
Sorry, but we won't do your homework for you. Please re-read our rules/policies:
Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.
#3
Re: C++ .Net LinkedList(T) Non-String Example Needed
Posted 07 March 2010 - 08:28 AM
Ferencn, on 07 March 2010 - 06:55 AM, said:
Sorry, but we won't do your homework for you.
If I must post some code to get the ball rolling, then here are some snippets that attempt to show what I have attempted. As I said, I've tried several hundred ways to get the compiler to play nice, but it refuses to comply. The project is megabytes in size, so I have had to perform generous carving in order to make a reasonably sized post of non-working code:
#pragma once
using namespace System;
using namespace System::Text;
using namespace System::Collections::Generic;
class CVia
{
public:
TVia info;
};
namespace DBXTest1 {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
<giant snip here>
private: System::Void button9_Click(System::Object^ sender, System::EventArgs^ e) {
LinkedList<CVia^>^ vialist = gcnew LinkedList<CVia^>;
// Should be zero as we have not loaded it yet:
textBox1->Text = "Found: " + vialist.count.ToString(); // this may need to be vialist->count.ToString(); but the compiler never gets this far
}
}
Now may we get back to the topic at hand? As I said, I have over a man day in on trying hundreds of different combinations to get this to work. Yes, indeed, it works as stated if I use strings. I have tried classes, structs (with which I admit I am most familiar), typedefs, templates (not useful here) to no avail.
I have written several linked list libraries myself in the past, but my downfall here is that I have been trying to use the .Net system rather than adding my own code when there is something built-in.
Thanks in advance for your help (assuming this thread may now proceed),
Kyle
#4
Re: C++ .Net LinkedList(T) Non-String Example Needed
Posted 07 March 2010 - 08:48 AM
I don't know the whacked-out half-Pascal syntax of C++ .NET, but wouldn't you create objects of type CVia and then add them to the list? The whole idea behind a generic LinkedList is ... it doesn't CARE what are the objects contained within. In C++:
class MyData
{
public:
MyData() : val_(0) {}
MyData(int val) : val_(val) {}
int getVal() const { return _val; }
private:
int val_;
};
int main()
{
int i = 0;
List<MyData *> myList;
for (; i < 5; ++i)
{
MyData *data = new MyData(i);
myList.AddFirst(data);
}
return 0;
}
#5
Re: C++ .Net LinkedList(T) Non-String Example Needed
Posted 07 March 2010 - 09:18 AM
Gosh, I wrote some stuff in Pascal back in the late 80s <shudder>. Anyway, yes, I should probably try to get away from .Net and get back to (real) C++. Your example looks very much like what I was trying to do using .Net's LinkedList(T). Thanks for the post.
-Kyle
-Kyle
Page 1 of 1

New Topic/Question
Reply



MultiQuote



|