help with overloading operators
ok i am doing something for school and part of it requires overloading the << operator. however i cannot for the life of me get this thing to work. the top code is the example he gave us and the bottom is what i am writing. they look the exact same other than the names and variables.
the error i get when i run the program is the
Error 15 error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'MyVector' (or there is no acceptable conversion) c:\users\tachikoma\documents\visual studio 2010\projects\project13\project13\driver.cpp 39
Code:
friend ostream& operator<<( ostream& theStream, const MyString& aString)
{
for (int i = 0; i < aString.size; i++)
{
theStream << aString.theString[i];
}
return theStream;
}
Code:
std::ostream& operator<< (std::ostream& out,const MyVector& myVec)
{
for (int i = 0; i < myVec.vectorSize; i++)
{
out << myVec.vectorPointer[i] << std::endl ;
}
return out;
}
ive tried sticking this in the implentation cpp file and the .h cpp file. i cannot edit the cpp file with the main() because thats provided and is used to check if this works or not. also his example is inside of one file class and all and the example is declared inside of the class using friend. seems i cant find where to stick it and get it to work? i tried using friend also but that didnt work didnt think it would but im probably doing it wrong
also do i need a prototype somewhere? if so where?
any help would be greatly appreciated