Странные дела начинаются с short getX (Vector *v, int pos)
— почему, если у вас вектор double
, вы возвращаете short
, а не double
?
Аналогично, если у вас
double sum=0;
...
return sqrtf(sum);
и функция возвращает double
, зачем же вычислять sqrtf
, а не sqrt
?…
void main()
неверно, нужен
int main()
Непонятно также
if (N==0) ;
И что вы хотите этим сказать? Кстати, на скриншоте у вас int main()
и return
после if (N==0)
, а вот это уже проблема: раз main
возвращает int
, то и return
должен быть со значением, return 0;
, например.
Вот все, что найдено компилятором. Правильно ли ваш код работает, а не компилируется — вопрос другой, не смотрел… Но даже навскидку:
void setN (Vector *v, int nr){
if (nr<1) v->n=1;
else v->n=nr;
}
Как я понимаю, это изменение размера (количества элементов) в векторе? Тогда почему вы не меняете выделенную память? А то ведь запросто может быть, что вы выделили 5 элементов, а потом сделали n
сотней, и здравствуй, выход за пределы массива…
gylayko 30 / 29 / 15 Регистрация: 28.09.2011 Сообщений: 449 |
||||
1 |
||||
05.02.2012, 12:49. Показов 9867. Ответов 29 Метки нет (Все метки)
Вот код программы, между void и main выдает ошибку declaration syntax error, что я не так делаю? моя первая прога на с++, поэтому прошу помощи)
0 |
5054 / 3115 / 271 Регистрация: 11.11.2009 Сообщений: 7,045 |
|
05.02.2012, 12:54 |
2 |
gylayko, по стандарту функция main должа возвращать значение типа int.
0 |
Полярный 476 / 448 / 158 Регистрация: 11.09.2011 Сообщений: 1,156 |
|
05.02.2012, 12:56 |
3 |
float x,y,a,b,z semicolon ; забыли silent_1991,
#include<math.h> Видимо в борланде работает -> на void ему пофиг.
0 |
silent_1991 |
05.02.2012, 12:57
|
Не по теме:
semicolon ; забыли А вот на это даже не смотрел))
0 |
BumerangSP 4299 / 1421 / 463 Регистрация: 16.12.2010 Сообщений: 2,939 Записей в блоге: 3 |
||||
05.02.2012, 13:01 |
5 |
|||
И на это вот:
0 |
5054 / 3115 / 271 Регистрация: 11.11.2009 Сообщений: 7,045 |
|
05.02.2012, 13:03 |
6 |
dimcoder, расширение не выдаёт борланд, ибо это Pure C (правда, насколько он Pure в борланде, я не знаю). А вот clrscr(); выдаёт.
0 |
30 / 29 / 15 Регистрация: 28.09.2011 Сообщений: 449 |
|
05.02.2012, 13:04 [ТС] |
7 |
gylayko, по стандарту функция main должа возвращать значение типа int. а у меня возвращает типа float, а что тогда нужно вместо void main() ? при замене переенных на тип int ошибка не пропадает)
0 |
silent_1991 5054 / 3115 / 271 Регистрация: 11.11.2009 Сообщений: 7,045 |
||||||||
05.02.2012, 13:06 |
8 |
|||||||
а у меня возвращает типа float ЩИТО?
при замене переенных на тип int А переменный тут при чём? По стандарту функция main может быть описана либо как
, либо как
0 |
BumerangSP 4299 / 1421 / 463 Регистрация: 16.12.2010 Сообщений: 2,939 Записей в блоге: 3 |
||||
05.02.2012, 13:09 |
9 |
|||
Так должно работать:
0 |
gylayko 30 / 29 / 15 Регистрация: 28.09.2011 Сообщений: 449 |
||||
05.02.2012, 13:12 [ТС] |
10 |
|||
Так должно работать:
все равно перед main та же ошибка!
0 |
silent_1991 5054 / 3115 / 271 Регистрация: 11.11.2009 Сообщений: 7,045 |
||||
05.02.2012, 13:15 |
11 |
|||
А вот так будет даже правильно работать. И будет выглядеть более-менее верно с точки зрения стиля.
0 |
Полярный 476 / 448 / 158 Регистрация: 11.09.2011 Сообщений: 1,156 |
|
05.02.2012, 13:16 |
12 |
все равно перед main та же ошибка! Среду разработки и компилер назовите. Скомпилел на борланд 3.1 все работает.
0 |
BumerangSP 4299 / 1421 / 463 Регистрация: 16.12.2010 Сообщений: 2,939 Записей в блоге: 3 |
||||
05.02.2012, 13:17 |
13 |
|||
http://liveworkspace.org/code/… c9afa745ce
1 |
gylayko 30 / 29 / 15 Регистрация: 28.09.2011 Сообщений: 449 |
||||
05.02.2012, 13:25 [ТС] |
14 |
|||
Среду разработки и компилер назовите. Скомпилел на борланд 3.1 все работает. тот же борланд 3.1 только через dosbox ибо 64 бит! Добавлено через 57 секунд
http://liveworkspace.org/code/… c9afa745ce а что за программа на фото? так ведь удобнее! без всяких досбоксов и т.д. работает?
0 |
4299 / 1421 / 463 Регистрация: 16.12.2010 Сообщений: 2,939 Записей в блоге: 3 |
|
05.02.2012, 13:26 |
15 |
а что это за программа на фото? Если Вы о ссылке, то это онлайн компилер. Кстати, вещь удобная)
0 |
30 / 29 / 15 Регистрация: 28.09.2011 Сообщений: 449 |
|
05.02.2012, 13:29 [ТС] |
16 |
Если Вы о ссылке, то это онлайн компилер. Кстати, вещь удобная) ну да, там все работает также как и у Вас! а через обычный компилятор борланд 3.1 нифига!
0 |
5054 / 3115 / 271 Регистрация: 11.11.2009 Сообщений: 7,045 |
|
05.02.2012, 13:32 |
17 |
обычный компилятор борланд 3.1 А потому что это не обычный компилятор. Это чрезвычайно древний компилятор, ему уже 20 лет. за это время успели выпустить три стандарта и несколько правок к ним.
0 |
4299 / 1421 / 463 Регистрация: 16.12.2010 Сообщений: 2,939 Записей в блоге: 3 |
|
05.02.2012, 13:34 |
18 |
ну да, там все работает также как и у Вас! а через обычный компилятор борланд 3.1 нифига! Это говорит о том, что код правильный. Но в онлайн компиляторе можно только проверять на ошибки. Поэтому стоит найти лучше что-нибудь поновей борланда, типа dev-cpp. Лучше конечно сразу MVC.
0 |
5054 / 3115 / 271 Регистрация: 11.11.2009 Сообщений: 7,045 |
|
05.02.2012, 13:36 |
19 |
MVC Не очень хороший совет, у него есть некоторые проблемы со стандартом.
dev-cpp Не такая уж она и новая. gylayko, советую среду, к которой можно подключить любой компилятор (на ваш выбор) и компилятор mingw, как можно новее (последняя релизная версия 4.6.2).
0 |
4299 / 1421 / 463 Регистрация: 16.12.2010 Сообщений: 2,939 Записей в блоге: 3 |
|
05.02.2012, 13:40 |
20 |
Не очень хороший совет, у него есть некоторые проблемы со стандартом. По крайней мере уж с такими ошибками должен справляться Слышал, что WxDev-cpp вроде как обновляется.
0 |
- Forum
- Beginners
- void main problem
void main problem
i am trying to use this given tutorial and main needs to be void for future tutorials, but every time i compile it as void, it gives an error saying main must return an int. Although on the tutorial it worked.
I know math.h and string do not need to be there, but it is for future purposes.
|
|
Last edited on
metulburr wrote: |
---|
main must return an int |
Last edited on
though it works on other peoples tutorials?
I would probably find a different tutorial…
The standard says main must return an int, but apparently some compilers will let you get away with void. I just tested with msvc 2010, and it will compile
without warning.
yeah dude, main() most definitely returns an int. Consider this simple boilerplate code:
int main(int nArgs, char* pszArgs)
its kinda just what i was told to impliment in all my main methods and i would be safe
Topic archived. No new replies allowed.
Looks like no one’s replied in a while. To start the conversation again, simply
ask a new question.
Hey there. I’ve just started taking a object-oriented C++ course online — it’s been a few years since I’ve programmed C++, although I’ve programmed C more recently. Anyways, they expect me to use Visual Studio as my compiler, but I’m not budging — Xcode is where I like to write my code, and I don’t feel like reinstalling Parallels. The problem is, the code I’m supposed to use for one of the exercises defines main() using ‘void’ instead of ‘int’. In my experience programming C (and C++ if I’m not mistaking), this has never been a problem. However, with Xcode I’m getting an error that says, «error: ‘::main’ must return ‘int'». Can anyone toss me some insight into why I’m getting this error, and how I may be able to correct it so that the compiler accepts main() as ‘void’? I’ve checked the project settings under «GCC 4.0 — Language», but I didn’t find anything I could recognize as relevant, other than «C Language Dialect» being set to C99, and I don’t think that’s the issue.
Any help is appreciated — thanks.
MacBook,
Mac OS X (10.5.8)
Posted on Sep 5, 2010 4:21 AM
Tron55555 wrote:
So I guess there’s no easy way around that then?
The easy answer is to use int. Like a number of things in the Windows world, «void main()» is flat-out syntactically invalid. The Microsoft Foundation Class library will not compile with a standards-compliant C++ compiler — because it isn’t valid C++. Microsoft’s compilers have switches to enable standards compliance, but you should never use them. GCC has switches to enable it to compile MFC, but no one ever uses them.
Apple gets a lot of press with the iPad and iPhone, but the reality is that Macs are still a distant minority in any corporate/educational environment. University professors, including those in Computer Science, are known for living 20 years in the past.
You are going to have to do what every Mac user in a computer science class has always done, write your code on your Mac because you love the Mac, then port it to Windows or whatever else. You are going to need Parallels for this course. The end result is that your code will be better than anyone else’s in the class. You have to write code good enough to satisfy two compilers and you will be a better programmer for it.
Posted on Sep 6, 2010 6:24 AM
error with ‘void main()’ in C++ tool
error: ‘::main’ must return ‘int’
#include <iostream>
using namespace std;
int i=1;
void main()
{
int i=i;
}
There was an error running:
error: '::main' must return 'int'
Reason: The C language standard allows the main function to be of type void. According to the C++ standard, main must be of type int.
Intelligent Recommendation
Main() error report-crazy delivery (not) return
Main’s error report-crazy delivery (not) return main() error Change the number of parameters Change parameter type But after all About the call stack Linux View Adjustment Windows View Adjustment (Com…
int main() void main()
Write a directory title here C/C++ :void main() C C++ void main int main( int argc, char *argv[], char *envp[] ) ? C/C++ :void main() void main(), , C , , void main(), int main() ? ? ? , C Primer Plus…
More Recommendation
error C4716 must return a value. Processing
problem The following error was reported, but I couldn’t find how to solve it. Record it here. error C4716: «TApamaInterface::GetEventValue»: Must return a value error C4716: «TApamaInt…