Making my own toString() method on c++ struct

I’m used to oveerriding the Java toString() method on my own objects in classes, but I’m not sure where I’m going wrong with the following code:

    struct Student {
    std::string name;
    int age;
    double finalGrade;

    std::string toString() {
        return "Name: " + name + "\n Age: " + age + "\n Final Grade: " + finalGrade;

I’m only beginning to learn c++ so any advice would be appreciated

Leave a Comment