4 Replies - 1229 Views - Last Post: 07 March 2010 - 09:18 AM Rate Topic: -----

#1 kda406   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 07-March 10

C++ .Net LinkedList(T) Non-String Example Needed

Posted 07 March 2010 - 07:37 AM

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

Is This A Good Question/Topic? 0
  • +

Replies To: C++ .Net LinkedList(T) Non-String Example Needed

#2 Ferencn   User is offline

  • D.I.C Regular
  • member icon

Reputation: 71
  • View blog
  • Posts: 322
  • Joined: 01-February 10

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.
:code:
Was This Post Helpful? 0
  • +
  • -

#3 kda406   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 07-March 10

Re: C++ .Net LinkedList(T) Non-String Example Needed

Posted 07 March 2010 - 08:28 AM

View PostFerencn, on 07 March 2010 - 06:55 AM, said:

Sorry, but we won't do your homework for you.

:D Please forgive me for finding that comment somewhat amusing. It has been several decades since 'homework', and the fact that I work 7 days a week means I'm never home. Nevertheless, I will attempt to stay on topic...

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
Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades   User is offline

  • Saucy!
  • member icon

Reputation: 6260
  • View blog
  • Posts: 24,030
  • Joined: 23-August 08

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;
}

Was This Post Helpful? 1
  • +
  • -

#5 kda406   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 07-March 10

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
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1