missing type specifier - int assumed. Note: C++ does not support default-int
Håller på att gå igeon "teach yourself C++ in 21 days". Och nu kommit till övning 5.7 som enligt boken ser ut
1: // Listing 5.7 - demonstrates use
2: // of default parameter values
3:
4: #include <iostream.h>
5:
6: int AreaCube(int length, int width = 25, int height = 1);
7:
8: int main()
9: {
10: int length = 100;
11: int width = 50;
12: int height = 2;
13: int area;
14:
15: area = AreaCube(length, width, height);
16: cout << "First area equals: " << area << "\n";
17:
18: area = AreaCube(length, width);
19: cout << "Second time area equals: " << area << "\n";
20:
21: area = AreaCube(length);
22: cout << "Third time area equals: " << area << "\n";
23: return 0;
24: }
25:
26: AreaCube(int length, int width, int height)
27: {
28:
29: return (length * width * height);
30: }
Jag har testat att både skriva den själv och ta ifrån boken, men jag får:
main.cpp(30): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int. Kan tillägga att jag kör Visual C++ Express 2010, ifall det är så att kompilatorerna är annorlunda eller något.
(notera att rad 30 är i mitt program, det är samma rad som 26 i exemplet)
Här är mitt om det underlättar något:
//Demonstrates use of default parameter values
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
int AreaCube(int length , int width = 25, int height = 1);
int main(){
int length = 100;
int width = 50;
int height = 2;
int area;
area = AreaCube(length, width, height);
cout << "First area equals: " << area << "\n";
area = AreaCube(length, width);
cout << "Second time area equals: " << area << "\n";
area = AreaCube(length);
cout << "Third time area equals: " << area << "\n";
system("pause");
return 0;
}
AreaCube(int length, int width, int height){
return (length * width * height);
}
4690K, 16GB ram, 1,25TB SSD, Radeon 7750
100% PASSIVT