-7

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

Connor
  • 3
  • 2
  • `stu.getthings;` isn't getthings a function? – drescherjm Mar 13 '18 at 21:38
  • 5
    I'm voting to close this question as off-topic because this question is beyond salvation. – SergeyA Mar 13 '18 at 21:39
  • 1
    I don't if I can go with beyond salvation, but the asker will certainly benefit more from [the guided learning of a good book or two](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) than anything Stack Overflow is intended to offer. – user4581301 Mar 13 '18 at 22:02

1 Answers1

-1

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++.

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055