I have a class Screen which has member content initialized using string(size_t, char) constructor.
#include<iostream>
#include <string>
struct Screen{
friend std::ostream& print(std::ostream& os,const Screen& screen);
Screen() = default;
Screen(std::size_t w, std::size_t h):width(w), height(h), content(w * h , ' '){}
Screen(std::size_t w, std::size_t h, char c):width(w), height(h), content(w*h, c){}
private:
std::size_t width = 24;
std::size_t height = 80;
std::size_t cursor = 0;
string content( (width * height), ' ');
};
I tried declaring a string in similar way inside main but I get the same error, I am not able to figure out what am I doing wrong here.
structures.cpp:16:21: error: expected identifier before '(' token
string content( (width * height), ' ');
^
structures.cpp:16:28: error: expected ')' before '*' token
string content( (width * height), ' ');
^
structures.cpp:16:28: error: expected ')' before '*' token
structures.cpp:16:22: error: expected ';' at end of member declaration
string content( (width * height), ' ');
^
structures.cpp:16:30: error: expected ';' at end of member declaration
string content( (width * height), ' ');
Aucun commentaire:
Enregistrer un commentaire