LINUX.ORG.RU

начинаюшему с++ помогите


0

0

Привет
ну вот купил себе книжку Седжвика и начал методично по ней учится но вот проблем небольшой.
у меня сентос 4.1
вот такая прога
#include <iostream.h>
#include <stdlib.h>

using namespace std;

struct node {
int item;
node* next;

node( int x, node* t) {
item = x;
next = t;
}
};

typedef node *link;

int main(int argc,
char *argv[]) {
int i = 0;
int N = atoi(argv[1]);
int M = atoi(argv[2]);

link t = new node(1,0);
t->next = t;

link x = t;

for (i = 2; i <= N; i++) {
x = (x->next = new node(i,t));
}
cout << "x->item " << x->item << endl;

while (x != x->next) {
for (i = 1; i < M; i++) {
x = x->next;
}
x->next = x->next->next;
}
cout << x->item << endl;
}

выполняю g++ josef_orig.cpp
выдает следующее
In file included from /usr/lib/gcc/i386-redhat-linux/3.4.3/../../../../include/c++/3.4.3/backward/iost ream.h:31,
from josef_orig.cpp:1:
/usr/lib/gcc/i386-redhat-linux/3.4.3/../../../../include/c++/3.4.3/backward/back ward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated.
josef_orig.cpp:16: error: `typedef struct node*link' redeclared as different kind of symbol
/usr/include/unistd.h:729: error: previous declaration of `int link(const char*, const char*)'
josef_orig.cpp:16: error: declaration of `typedef struct node*link'
/usr/include/unistd.h:729: error: conflicts with previous declaration `int link(const char*, const char*)'
josef_orig.cpp:16: error: declaration of `typedef struct node*link'
/usr/include/unistd.h:729: error: conflicts with previous declaration `int link(const char*, const char*)'
josef_orig.cpp: In function `int main(int, char**)':
josef_orig.cpp:24: error: expected `;' before "t"
josef_orig.cpp:24: warning: statement is a reference, not call, to function `link'
josef_orig.cpp:25: error: `t' undeclared (first use this function)
josef_orig.cpp:25: error: (Each undeclared identifier is reported only once for each function it appears in.)
josef_orig.cpp:27: error: expected `;' before "x"
josef_orig.cpp:27: warning: statement is a reference, not call, to function `link'
josef_orig.cpp:30: error: `x' undeclared (first use this function)

в чем проблема не пойму обьясните

anonymous

читай внимательней:

>Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated.

соответственно вместо #include <iostream.h> нужно #include <iostream>

>josef_orig.cpp:16: error: `typedef struct node*link' redeclared as different kind of symbol /usr/include/unistd.h:729: error: previous declaration of `int link(const char*, const char*)' josef_orig.cpp:16: error: declaration of `typedef struct node*link' /usr/include/unistd.h:729: error: conflicts with previous declaration josef_orig.cpp:16: error: `typedef struct node*link' redeclared as different kind of symbol /usr/include/unistd.h:729: error: previous declaration of `int link(const char*, const char*)' josef_orig.cpp:16: error: declaration of `typedef struct node*link' /usr/include/unistd.h:729: error: conflicts with previous declaration `int link(const char*, const char*)'

говорит что link уже определена как функция `int link(const char*, const char*)' в файле /usr/include/unistd.h посему придумай другое имя. другие ошибки сыпятся из-за этой

ale ★★
()

ой спасибо люди дорогие.
пойду домой смотреть и тестить и задавать новые вопросы.

anonymous
()

еще вместо stdlib.h - cstdlib

anonymous
()
Ответ на: комментарий от AnToXa

>и не писать using namespace std; там где не надо :)

Кстати, да. В данном случае можно обойтись лишь using std::cout;

php-coder ★★★★★
()
Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.