Declaring a string array in the class header file - does the compiler consider the string to be a variable name?

Hi everyone, I need a little hand with declaring a string array in my C ++ class header file.

atm 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 get a compiler error message:

In file included from model-view.cpp:11:
Maze.h:14: error: ISO C++ forbids declaration ofstringwith no type
Maze.h:14: error: expected ‘;’ before ‘*’ token

and the only meaning that makes for me is that for some reason it thinks that I want the string to be a variable name not as a type declaration.

If someone could help me, it would be fantastic, looked at it for a while, and it gave me shats lol.

Greetings guys

+3
source share
2 answers

: std::string.

, : . - .

, , , . . std::vector<std::string>. .

+10

++ STL SGI.

: http://www.sgi.com/tech/stl/Vector.html

: http://www.sgi.com/tech/stl/basic_string.html

, [] operator. intems , insert, :

v.insert(v.end(), new_item);.

a new_item v.

Vector, std::vector<std::string>.

0

Source: https://habr.com/ru/post/1742270/


All Articles