[C++] klasy, konwersje

0

Witam, mam problem z moim programem, który bezproblemu kompiluje się pod Visualem, a Codeblocks wypluwa błedy o niepasujacych funkcjach [code]|21|error: no matching function for call to `TString::TString(TString)'|[/code]

Aby poniższy kod skompilował się w codeblocksie musiałem dodac operator w klasie TString zwracajacy char*. Czym spowodowany jest taki rozrzut, dlaczego nie moge skompilowac nastepujacej linkijki?[code] obiekt ob3(kolor(0,0,0),ts2);[/code]
[code]/main.cpp/
#include <iostream>
#include "TString.h"
#include "kolor.h"
#include "obiekt.h"

using namespace std;

int main()
{

TString ts1, ts2("ts2_tekst"), ts3('b', 4);
ts1.print();
ts2.print();
ts3.print();
cout << endl;

kolor kol1;
kolor kol2(ts2);
kolor kol3(1, 3, 4);
kolor kol4(3 ,5, "nazwa kol");
kolor kol5(255,255,255, TString("nowy"));
kol1.print();
kol2.print();
kol3.print();
kol4.print();
kol5.print();
cout << endl;

obiekt ob1;
obiekt ob2(ts3);

// obiekt ob3(kolor(0,0,0),ts2);
obiekt ob4(TString("proba operatora"));
ob1.print();
ob2.print();
// ob3.print();
ob4.print();
return 0;
}

[/code]
[code]
/TSTRING.cpp/
#include <iostream>
#include <cstring>
#include "TString.h"

TString::TString(void)
{
str = 0;
len = 0;
cout << "Konstruktor bezarg. TString" << endl;
}

TString::TString(char * st)
{
len = strlen(st);
str = new char[len + 1];
strcpy(str,st);
cout << "Konstruktor TString(char * st)" << endl;
}

TString::TString(char zn , int leng )
{
len = leng;
str = new char[len+1];
memset(str, zn, len);
str[len] = 0;
cout << "Konstruktor TString(char zn , int leng )" << endl;
}

TString::TString( TString & n)
{
len = n.len;
if(len)
{
str = new char[len + 1];
strcpy(str,n.str);
}
else
str = NULL;
cout << "Konstruktor TString(TString &)" << endl;
}

TString::~TString(void)
{
if (len != 0)
{
delete [] str;
}
cout << "Destruktor klasy TString" << endl;
}

[/code]
[code]/* TString.h.*/
#ifndef TSTRING_H_INCLUDED
#define TSTRING_H_INCLUDED
#include <iostream>
#include <cstring>

using namespace std;

class TString
{
public:
TString(void);
TString(char * st);
TString(char zn , int leng );
TString( TString & n);
~TString(void);
// operator char*()
// {
// return str;
// }
void print(void)
{
if(str)
cout << str << endl;
else
cout << endl;
}
private:
int len;
char * str;
};

#endif // TSTRING_H_INCLUDED

[/code]
[code] /color.cpp/
#include <iostream>
#include "kolor.h"
#include "TString.h"
using namespace std;

//kolor::kolor(void): nazwa("bez argumentowy")
//{
// R = 0;
// G = 0;
// B = 0;
// cout << "konstruktor kolor(void)"<<endl;
//}

kolor::kolor(TString & st):nazwa(st)
{
R = 0;
G = 0;
B = 0;
cout << "konstruktor kolor(TString st)"<< endl;
}
kolor::kolor(int r, int g, int b)
{
R = r;
G = g;
B = b;
cout << "Konstruktor kolor(int r, int g, int b) "<<endl;
}

kolor::kolor(int rg, int b, char * st): nazwa(st)
{
R = G = rg;
B = b;
cout << "konstruktor kolor(int rg, int b, char * st)"<< endl;

}

kolor::kolor(int r, int g, int b, TString nap):nazwa(nap)
{
R = r;
G = g;
B = b;
}

kolor::~kolor(void)
{
cout << "Destruktor klasy kolor"<<endl;
}

[/code]
[code]/kolor.h/
#ifndef KOLOR_H_INCLUDED
#define KOLOR_H_INCLUDED
#include <iostream>
#include "TString.h"

using namespace std;

class kolor
{
public:
// kolor(void);
kolor(TString & st);
kolor(int r =0, int g=0, int b=0);
kolor(int rg, int b, char * st);
kolor(int r, int g, int b, TString st);
~kolor(void);

void print(void)
{
	cout << "R = " << R << " G = " << G << " B = "<< B <<   endl;
	nazwa.print();
}

private:
TString nazwa;
int R, G, B;
};

#endif // KOLOR_H_INCLUDED

[/code]
[code]/obiekt.cpp/
#include <iostream>
#include "obiekt.h"
#include "kolor.h"
#include "TString.h"
using namespace std;

obiekt::obiekt(void): nazwa("bez nazwy")
{
cout<<"konstruktor obiekt(void)"<<endl;
}
obiekt::obiekt(TString st): kol(0, 0, 0), nazwa(st)
{
cout<<"konstruktor obiekt(TString st)"<<endl;
}
obiekt::obiekt(kolor ko, TString st): kol(ko), nazwa(st)
{
cout<<"konstruktor obiekt(kolor ko, TString st)"<<endl;

}

obiekt::~obiekt(void)
{
cout << "destruktor klasy obiekt" << endl;
}

[/code]
[code]/obiekt.h/
#ifndef OBIEKT_H_INCLUDED
#define OBIEKT_H_INCLUDED
#include <iostream>
#include "kolor.h"
#include "TString.h"

using namespace std;

class obiekt
{
public:
obiekt(void);
obiekt(TString st);
obiekt(kolor ko, TString st);
~obiekt(void);
void print(void)
{
kol.print();
nazwa.print();
}
private:
kolor kol;
TString nazwa;
};

#endif // OBIEKT_H_INCLUDED

[/code]

0

który bezproblemu kompiluje się pod Visualem,
a nie powinien.

a Codeblocks wypluwa błedy o niepasujacych funkcjach
i prawidłowo.

1 użytkowników online, w tym zalogowanych: 0, gości: 1