[QUOTE=Salem;1110664]What T are you using as the type for your list?

If it's a class, and it lacks a copy constructor, then your internal assignments are broken (when you copy the data)[/QUOTE]

Very true, for now I just designed the class to take simple types (i.e. chars, ints, floats....). Here's the source file for testing the template:

[CODE]
// TEST program for "Linked Node" & "Linked List"

include <iostream>

include <string>

include "Linked List 13_9_1.h"

using namespace std;

int main()
{
cout << "Creating a linked list of INTs with 5 elements:\n";
LinkedList<int> tList;

tList.append(3);
tList.append(5);
tList.append(7);
tList.append(9);
tList.append(11);
tList.append(13);

cout << "\nOutputting list: ";
tList.printlist();

cout << "\nCreating new list based on old list:\n";
LinkedList<int> newList(tList);
cout << "\nOutputting list: ";
newList.printlist();

}
[/CODE]

You're absolutely right I forgot to initialize, thanks for the tip :) I added mFirst = 0 and mLast= 0. The error, however, still persists.

I read that this may have to do with trying to delete a dyn mem allocation that was already deleted, but I don't see any problem with my destroy() routine....

I seemed to have figured it out, C++ doesn't seem to like compiling header files alone (at least in terms of templates perhaps). I implemented a test source file with it and now it compiles fine.

Now, however, I have another problem (of course!): I run accross the following assertion failure after running the program in debug :

_BLOCK_TYPE_IS_VALID(pHead -> NBlockUse)

Although my test .cpp isn't shown here, in it I simply instantiate an object of LinkedList with the default constructor (which works fine).

On the other hand, I then instantiate another object using the class's copy constructor and it creates this error, any ideas?

Thanks to all,
Ivan

Hi everyone,

For practice I am trying to code a simplified version of the template "std::list" but have come accross the LNK1120 + LNK2001 errors.

After looking in Visual Studio's documentation and some investigation, it seems the two most common causes are: 1) invalid calls in the code to things which don't exist, or 2) invalid project settings.

I can't seem to find any of these two problems in my code/project. On the other hand, I have also heard that these errors may be the result of some limitation in C++ where one template cannot call another one defined outside the calling header file, but I'm not sure about this last one.

In any case, I would really appreciate if someone could take a look at the following code and give me a hand. Thanks!

[CODE]

ifndef LINKEDLIST_H

define LINKEDLIST_H

include <iostream>

include <string>

include "Linked Node 13_9_1.h"

using namespace std;

template <typename T>
class LinkedList
{
public:
LinkedList();
~LinkedList();
LinkedList(const LinkedList& rhs);

void append(T copieddata);
void printlist();
void destroy();

private:
LinkedNode mFirst;
LinkedNode
mLast;
};

template <typename T>
LinkedList<T>::LinkedList()
{
mFirst = 0;
mLast= 0;
}

template <typename T>
LinkedList<T>::~LinkedList()
{
destroy();
}

template <typename T>
void LinkedList<T>::destroy()
{
if (mFirst != 0 )
{
LinkedNode<T> current = mFirst;
while ( current != 0 )
{
LinkedNode<T>
oldnode = current;
current = current->next;
delete oldnode;
oldnode = 0;
}
}
}

template <typename T>
void LinkedList<T>::printlist()
{
LinkedNode<T>* current = mFirst;
while ( current != 0 )
{
cout ...

Just a quick intro about me: I'm a 30 year old guy going through C++ and directX courses from the Game Institute. I signed up to Daniweb for additional support to an already well designed program (IMO). Once I finish, I'm hoping to get 2 or 3 other like-minded individuals to work on a small game for digital distribution.

Pleased to meet you all!

[QUOTE=Agni;1104449]Consider Abin to be of size 10 and Bbin to be of size 8 now according to your code since Abin.size() > Bbin.size(), Cbin is resized to Abin.size(), hence 10

Then jump to line 25, you have a loop which goes upto CbinSize, which is 10 and you end up accessing Bbin[8] which could either throw an error or end up giving out some garbage.[/QUOTE]

Wow, I can't believe I didn't see that, thank you very much!

One of the requirements imposed on this exercise is to give binary output as a char string but not necessarily perform the calculations in this form.

I just realized that bit operations work fine on integers: I could have done all the operations on A and B as ints and then convert the resulting C back to binary, a lot more efficient!

Cheers,
Ivan

Hi everyone,

This is my first post so go easy on me please :). I am trying to compile a simple program that takes two binary numbers and computes a third based on bit operations (i.e. C = A&B, C = A|B etc....) but I run into the "vector subscript out of range error" even though I have carefully tried to ensure that I'm not stepping out of index bounds.

Is anyone able to help me with this?

NOTE: The binary numbers are stored as vector arrays of type char

[CODE]
int main()
{
// Request and obtain valid decimal numbers
int A = obtaindec('A');
int B = obtaindec('B');

// Convert A and B to binary and store as vector<char> arrays

vector<char> Abin = dectobinstring('A', A);
vector<char> Bbin = dectobinstring('B', B);

// Create C based on the largest size of the other two
vector<char> Cbin;
if ( Abin.size() > Bbin.size() )
    Cbin.resize(Abin.size());
else
    Cbin.resize(Bbin.size());
int Cbinsize = Cbin.size();
for ( unsigned int x = 0; x < Cbinsize; ++x )
    Cbin[x] = 48;

// Now recalculate C as the result of relational operations
// on A and B

for ( unsigned int x = 0; x < Cbinsize; ++x )
    if ( Abin[x] == 49 && Bbin[x] == 49 )
        Cbin[x] = 49;

cout << "\n\nA & B = ";
 for ( unsigned int x = 0; x < Cbinsize; ++x )
    cout << Cbin[x];
cout << endl;

}
[/CODE]