C++ error trying to return pointer that points to dynamic array in Visual Studio

I am having some issues trying to return a pointer that points to a dynamic array in C++ while overloading the stream insertion operator. I am using Visual Studio 2017. Here is the relevant code. If you think it's necessary I'll post all of my code but I didn't want to make you read the whole thing when I'm only having problems with this one bit currently. Also, the assignment this is for requires me to use dynamic arrays, so please don't tell me to just use std::vector.

Student.h

    class Student
{
private:
string firstname;
string lastname;
unsigned int id;
unsigned int items_checkedout;
string *things = new string[items_checkedout];
}

Student.cpp

const string* Student::getthings()
{
    return things;
}
const string Student::getFirstName()
{
return firstname;
}

const string Student::getLastName()
{
    return lastname;
}

const int Student::getID()
{
return id;
}

unsigned int Student::CheckoutCount()
{
return items_checkedout;
}

    ostream& operator<<(ostream& out, const Student& stu)
{
    const string *things = stu.getthings;


out << stu.getID << " " << stu.getFirstName << " " << stu.getLastName << 
endl;
out << stu.CheckoutCount;
if (stu.CheckoutCount > 0)
{
    for (int i = 0; i < stu.CheckoutCount; i++)
    {
        out << things[i];
    }
}
}

Here are the errors I'm getting:

Error C3867 'Student::getthings': non-standard syntax; use '&' to create a pointer to member line 184

Error C2276 '*': illegal operation on bound member function expression line 187

Error C3867 'Student::CheckoutCount': non-standard syntax; use '&' to create a pointer to member line 188

"same thing, line 189

Error C2296 '>': illegal, left operand has type 'unsigned int (__thiscall Student::* )(void) line 189

Error C2297 '>': illegal, right operand has type 'unsigned int (__thiscall line 189

Error C3867 'Student::CheckoutCount': non-standard syntax; use '&' to create a pointer to member line 191

Error C2446 '<': no conversion from 'unsigned int &(__thiscall Student::* )(void)' to 'int' line 191

1 answer

  • answered 2018-03-13 21:38 Lightness Races in Orbit

    Your class definition lacks a ; at the end, and any of the member functions you later define.

    Your Student.cpp lacks a #include "Student.h" at the start.

    Your Student.h lacks several standard #includes at the start.

    These expressions stu.getFirstName are probably supposed to be like stu.getFirstName().

    Pick up a book on introductory C++.