Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C++
// ConsoleApplication5.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <windows.h>
#include <iostream>
#include <string.h>
#include <string>
#include <cstdlib>

char x;
using namespace std;

char map[4][4];

map[1][1] = {x};

int main()
{
	return 0;
}

_____________________________________________________________________

When I compile I get the following errors :

Error 1 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

Error 2 error C2369: 'map' : redefinition; different subscripts

Error 3 IntelliSense: this declaration has no storage class or type specifier

I'm running this on Microsoft Visual Studio 2012 Express on Windows 7
Posted
Updated 6-Jan-14 7:14am
v2
Comments
joshrduncan2012 6-Jan-14 13:15pm    
Please show us what line each of these errors are pointing to.

You can only write declarations outside of a method scope, so when you write:

C++
map[1][1] = {x};


That is an invalid statement because it is not a declaration. In order to use that, put it inside the main() method, like:

C++
int main()
{
    map[1][1] = x;
    return 0;
}


However, since you did not initialize x with any value, it will be some random value or you may get a warning about using an uninitialized variable.
 
Share this answer
 
Comments
Thomas Daniels 6-Jan-14 13:19pm    
You beat it to me! +5!
Try this code:
C++
#include "stdafx.h"
#include <windows.h>
#include <iostream>
#include <string.h>
#include <string>
#include <cstdlib>

char x;
using namespace std;

char map[4][4];



int main()
{
	map[1][1] = { x };
	return 0;
}
</cstdlib></string></string.h></iostream></windows.h>

You just need to move the map[1][1] = { x }; line into the main() method. The reason: you can put variable declarations outside functions, but if you try to change the value of this variable, then this has to be inside a function.
 
Share this answer
 
v2
Comments
Ron Beyer 6-Jan-14 13:20pm    
5'd too!
Thomas Daniels 6-Jan-14 13:21pm    
Thank you!
Member 10506844 6-Jan-14 14:32pm    
Is it possible for me to move it to a function, I'm just curious.
Thomas Daniels 7-Jan-14 12:24pm    
Yes, you can, as you can see in my answer. If you mean that you want to move it outside a function, then you can't.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900