Witam,
Mam następujący problem. Zadeklarowałem i zdefiniowałem klasy w osobnych plikach. Zrobiłem konstruktory ale mam problem z napisaniem metody print() dla klasy Kolor. Nie wiem jak wyświetlić nazwę czyli Pole typu Tstring będące inną klasą.
Klasa Kolor (deklaracja):
#pragma once
#include <iostream>
#include "TString.h"
using namespace std;
class Kolor
{
int R,G,B;
Tstring nazwa;
public:
Kolor();
Kolor(Tstring);
Kolor(Tstring, int a, int s, int d);
Kolor(int x, int y, int z);
~Kolor();
void print()
{ <b>??????????????????????</b>
};
};
Klasa kolor - .cpp
#include "kolor.h"
Kolor::Kolor()
{
cout << "konstruktor bezargumentowy Kolor" << endl;
}
Kolor::Kolor(Tstring p)
{
nazwa=p;
cout << "konstruktor Tstring - argumentowy Kolor" << endl;
}
Kolor::Kolor(Tstring p, int a, int s, int d)
{
nazwa=p;
R=a;
G=s;
B=d;
cout << "kontruktor 4 - argumentowy Kolor" << endl;
}
Kolor::Kolor(int x, int y, int z)
{
R=x;
G=y;
B=z;
cout << "kontruktor 3 - argumentowy Kolor" << endl;
}
Kolor::~Kolor()
{
cout << "destruktor Kolor" << endl;
};
a Tstring wyglada tak - .h
#pragma once
#include <iostream>
using namespace std;
class Tstring
{
char *str;
int len;
public:
Tstring();
Tstring(char *);
Tstring(char, int);
~Tstring();
void print()
{
cout << "zawartosc pola str :" << str << endl;
};
};
i .cpp
#include "TString.h"
Tstring::Tstring(){str = 0; len = 0;
cout << "Konstruktor bezargumentowy Tstring"<< endl;}
Tstring::Tstring(char * A)
{
len=strlen(A);
str = new char[len+1];
strcpy(str,A);
cout << "Konstruktor char* - argumentowy Tstring"<< endl;
}
Tstring::Tstring(char A, int l)
{
len=l;
str = new char[len+1];
for(int i=0;i<len;i++)
str[i]=A;
str[len]=0;
cout << "Konstruktor char, int argumentowy Tstring"<< endl;
}
Tstring::~Tstring()
{ if(str)
delete []str;
cout << "destruktor Tstring"<< endl;
}
jak napisać metodę print() w klasie Kolor by wyświetlała RGB i nazwę?
z góry dzięki za pomoc