테이블을 만들 수있는 벡터 클래스를 사용하여 에뮬레이션하는 테이블이 필요한 프로그램을 작성하고 있습니다. 그러나 vec_data 제외한 클래스 테이블의 항목을 볼 수 없습니다. 이 클래스의 공용 멤버에 액세스 할 수없는 이유는 무엇입니까? 어떤 이유로 MSVC++ Intellisense는 vec_data 만 볼 수 있습니다. 예를 들어클래스가 공용 멤버에 액세스 할 수 없습니다. C++
template<class T>
class table
{
private:
T* vec_data;// initialize T
struct tblarray : public T
{
std::vector<T> vecTbl[];
bool operator[](unsigned int i) { return vecTbl[i]; } //redefine operator[] to accept unsigned int
static void operator new(double n) //redefine new operator
{
void *d;
if(n < 0) throw std::exception("Invalid Allocation to Negative number!");
if(assert((d=malloc(n)) != 0) = 0) throw std::bad_alloc;
return d;
}
void operator delete(void *d) //redefine delete operator
{
if(assert((free(p))) = 0) throw std::exception("Invalid Free of specified data!");
}
tblarray(const T&, unsigned int size) : T //one constructor
{
vecTbl = this.new std::vector<T>[reinterpret_cast<double>(size)];
}
~tblarray() //one destructor
{
this.delete(vecTbl);
}
}
public:
table(const T&, unsigned int size) : T
{
this.tblarray.tblarray(T, size);
}
~table()
{
this.tblarray.~tblarray();
}
}
:
table<int> tblOne; //legal
table.table(int, 123); //not legal(probably not legal anyways, but intellisense says the function does not exist?)
'table (const T &, unsigned int size)'은 생성자이며 생성자는 이름이 지정되지 않고 직접 호출 할 수 없습니다. (소멸자도 공식적으로 이름이 붙지 않지만 직접 호출 할 수 있습니다.) 시간의 99.9 %를 차지하지 않아야합니다. –
하지만이 작업은 다음과 같습니다. 표 * tblOne = new 표 (123) throws : 적절한 생성자가 int에서 int로 변환되지 않습니다. 테이블 비록 constructor에 int 타입의 보조 param을 가지고 있습니다. –
7c00h
나는 당신이 무엇을하고 있는지 전혀 모른다고 생각합니다.'table (const T &)'는 복사 생성자이고'table (unsigned int)'는 변환 생성자가됩니다. 가지고있는 것은 정상적인 두 매개 변수 생성자입니다. 그것을 사용하려면 _two_ 매개 변수를 전달해야합니다. 하나는'table'이고, 하나는'unsigned int'입니다. –