On Thu, 12 Dec 2019 07:25:17 GMT, Erdem wrote:
When I try to access __gshared variable studentStore, I get undefined identifier error.
source/app.d(26,24): Error: undefined identifier studentStore, did you mean class StudentStore?
What might be the cause of this?
Ok. I've recognized that my initial code was faulty. Here is the working one.
import vibe.d;
struct Student
{
string name;
uint number;
}
class StudentStore
{
Student[][string] store_;
static Student[0] empty_;
Student[] getNotes(string id)
{
return (id in store_) ? store_[id] : empty_;
}
}
private __gshared StudentStore studentStore;
shared static this()
{
studentStore = new StudentStore();
}
void listStudents(HTTPServerRequest req, HTTPServerResponse res)
{
auto allstudents = studentStore.getNotes(req.session.id);
}
void main()
{
auto router = new URLRouter;
router.get("/", staticTemplate!"index.dt");
router.get("*", serveStaticFiles("public/"));
auto settings = new HTTPServerSettings;
settings.port = 8080;
settings.bindAddresses = ["::1", "127.0.0.1"];
listenHTTP(settings, router);
logInfo("Lütfen tarayıcınızda http://127.0.0.1:8080/ adresini açınız.");
runApplication();
}
Should I move the line within shared static this {} which constructs a student Store object to main function ? Or leave as is.