hmm....why I can't get the output?? any wrong ?? thx for helping...

#include <iostream>
using namespace std;

const int SIZE = 3;
class Course {
    string* students;
  public:
    Course (string* students);
    ~Course ();
    void print();
};

Course::Course (string* students) {
    students = new string[SIZE];
    for(int i=0; i<SIZE; i++){
         students[i]=Course.students[i];
        }
}

Course::~Course() {
  delete [] students;
}

void Course::print() {
  cout << "Students = ";
  for (int i = 0; i < SIZE; i++)
     cout << students[i] << " ";
  cout << endl;
}

int main() {
  string s1[] = {"aaa", "bbb", "ccc"};
  Course c1(s1);
  c1.print();
  string s2[] = {"xxx", "yyy", "zzz"};
  Course c2(s2);
  c2.print();

  return 0;
}

Edited 3 Years Ago by mike_2000_17: Fixed formatting

first please use the [ code ] and [ / code ] tags.

The line

students[i]=Course.students[i];

contain an error.it should be like this.

Course::Course (string* students) 
{
    [B]this->students = new string[SIZE];[/B]
    for(int i=0; i<SIZE; i++)
    {
           [B]this->students[i]=students[i];[/B]
    }
}

you have to use this , and note that this is a pointer so you have to use '->' operator.

Edited 6 Years Ago by NicAx64: n/a

This question has already been answered. Start a new discussion instead.