Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
–
I placed comments where I made changes. The main fix is to pass your object by reference, especially to
Getdata()
. You passed a copy, put data into the copy, and when the function ended, the copy goes away and your original object was never touched.
#include <iostream>
using namespace std;
template <class T>
class Array {
public:
T U[10];
friend void DataOut(
const Array<string>&); // CHANGED: Need to take object by reference
friend void GetData(Array<string>&); // SAME
void DataOut(const Array<string>& Array1) { // SAME
cout << Array1.U[0];
void Getdata(Array<string>& Array1) { // SAME
cin >> Array1.U[0];
// cin.clear(); // CHANGED: Why?
int main() {
Array<string> Arr1;
Getdata(Arr1);
DataOut(Arr1);
–
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.