This is my first attempt to create a basic list (i need this at school) and i get a strange error.
This is the script:
#include "stdafx.h"
#include<iostream>
#include<conio.h>
using namespace std;
using namespace System;
using namespace System::Threading;
struct nod
{
int info;
nod *leg;
};
int n, info;
nod *v;
void main()
{
....
addToList(v, info); //I get the error here
showList(v); //and here
}
void addToList(nod*& v, int info)
{
nod *c = new nod;
c->info=info;
c->leg=v;
v=c;
}
void showList(nod* v)
{
nod *c = v;
while(c)
{
cout<<c->info<<" ";
c=c->leg;
}
}
The exact error is: error C3861: 'addToList': identifier not found
I dont know why I get this... sorry if it is a stupid question but i am very new at this. Thanks for understanding.
you need to put a forward declaration to use a method before it's implementation. Put this before main :
void addToList(nod*& v, int info);
In C/C++ a method should be used only after it's declaration. To allow recursive call between different methods you can use forward declarations in order to allow the use of a function/method that will be forward implemented.