Declaring a string array in class header file - compiler thinks string is variable name?
Posted
by Dave
on Stack Overflow
See other posts from Stack Overflow
or by Dave
Published on 2010-04-22T12:07:14Z
Indexed on
2010/04/22
12:13 UTC
Read the original article
Hit count: 296
Hey everybody, I need a bit of a hand with declaring a string array in my class header file in C++.
atm it looks like this:
//Maze.h
#include <string>
class Maze
{
GLfloat mazeSize, mazeX, mazeY, mazeZ;
string* mazeLayout;
public:
Maze ( );
void render();
};
and the constructor looks like this:
//Maze.cpp
#include <GL/gl.h>
#include "Maze.h"
#include <iostream>
#include <fstream>
Maze::Maze( )
{
cin >> mazeSize;
mazeLayout = new string[mazeSize];
mazeX = 2/mazeSize;
mazeY = 0.25;
mazeZ = 2/mazeSize;
}
I'm getting a compiler error that says:
In file included from model-view.cpp:11:
Maze.h:14: error: ISO C++ forbids declaration of ‘string’ with no type
Maze.h:14: error: expected ‘;’ before ‘*’ token
and the only sense that makes to me is that for some reason it thinks I want string as a variable name not as a type declaration.
If anybody could help me out that would be fantastic, been looking this up for a while and its giving me the shits lol.
Cheers guys
© Stack Overflow or respective owner