-
friend ostream problem
I have a class something like this
Code:
template class<T>
class A{
private:
T m;
T n;
List<T> *start;
List<T> *end;
public:
...
friend ostream & operator<<(ostream &os, A<T> & dy);
}
Code:
template class<T>
ostream & operator<<(ostream &os, A<T> & dy)
{
os<<dy.start->x<<dy.start->y<<dy.start->value;
return os;
}
x,y and value are some public elements of List<T>
I do some operations on list and when I want to print the list elements , I wrote something like in implementation of operator<<, but i get segmentation error. How can i reach those x,y,and value in operator<< implementation?
-
I note that the overload should be declared as:
Code:
friend std::ostream & operator<<(std::ostream &os, const A<T> & dy);
That aside, the problem is probably with some other code, e.g., you forgot to initialise something, or you accessed something out of bounds, or you dereferenced a null pointer, etc.
-
yeah i think i make one of those, but for example when i write below in other functions
Code:
cout<<start->x<<start->y<<start->value;
i get what i want ; but in operator<< implementation this does not work :S
-
Sorry, but there is just not enough information for me to help you. I suggest that you post the smallest and simplest compilable program that demonstrates the error.
-
From the looks of it, this should be relevant, but it is unclear why you don't get a linker error.
-
I do some stuff there to avoid linker errors
how should i use this at there?