我正在嘗試在C++中編寫一個函數,用它的值來排序整數。例如,如果A = 5,B = 2和c = 3,那麼它會命令他們B,C,一個嘗試按值排序整數
這是代碼,我迄今爲止:
#include "stdafx.h"
#include <iostream>
using namespace std;
void sortThreeIns(int a, int b, int c);
int main()
{
int a = 3;
int b = 4;
int c = 1;
sortThreeIns(a, b, c)
{
if (a > b)
{
int temp = a;
a = b;
b = temp;
}
if(a > c)
{
int temp = a;
a = c;
c = temp;
}
if (b > c)
{
int temp = b;
b = c;
c = temp;
}
return 0;
}
return 0;
}
這使返回箱6語法錯誤,如「預期的一個;」和「語法錯誤:如果」但我不知道爲什麼? 有什麼幫助嗎?
哇,不,回到本書,這是無效的C++。 – DeiDei
你不能在另一個函數中放置一個函數定義。 – user463035818
C++中不允許嵌套函數。 'sortThreeIns'必須在'main'函數之外定義,並且像另一個函數一樣調用。請[找一本好初學者的書或教程閱讀](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list)。 –