-1
다음과 같이 해당 메소드가 객체를 매개 변수로 허용하는 클래스가 있습니다. 나는이 기능을 테스트 할 때C++에서 매개 변수로 함수에 여러 객체를 전달하는 방법
는template <typename T> class Matrix{
private:
matrixNode<T>* rear=0;
std::vector<int> rows;
std::vector<int> cells;
std::vector<matrixNode<T>*> listofAddedNodes;
void generatetableRowCellArrays(int rowSize,int cellSize){
for (int i=0;i<rowSize;i++){
rows.push_back(i);
}
for (int i=0;i<cellSize;i++){
cells.push_back(i);
}
}
public:
Matrix(int rowSize,int cellSize){
generatetableRowCellArrays(rowSize,cellSize);
}
void ceateSparsMatrix(matrixNode<T> *node){
matrixNode<T> *mxNode=(matrixNode<T>*)malloc(sizeof(matrixNode<T>));
mxNode=node;
if(rear!=0){
rear->PL=(matrixNode<T>*)&rows[mxNode->line];
rear->PC=(matrixNode<T>*)&cells[mxNode->column];
}
rear=mxNode;
listofAddedNodes.push_back(mxNode);
}
void ceateSparsMatrix(matrixNode<T> node,int SpecificRow,int specificCell){
matrixNode<T> *mxNode=(matrixNode<T>*)malloc(sizeof(matrixNode<T>));
mxNode=node;
if(rear!=0){
rear->PL=&rows[SpecificRow];
rear->PC=&cells[specificCell];
}
rear=mxNode;
listofAddedNodesPointers.push_back(&rear->value);
}
void showAllAddedNodes(){
for(int i=0;i<listofAddedNodes.size();i++){
printf("|----------------------------|\n");
printf("|Value | %d |\n",listofAddedNodesPointers[i]->value);
printf("|Coll | %d |\n",listofAddedNodesPointers[i]->column);
printf("|Line | %d |\n",listofAddedNodesPointers[i]->line);
printf("|PC | %d |\n",listofAddedNodesPointers[i]->PC);
printf("|PL | %d |\n",listofAddedNodesPointers[i]->PL);
printf("|----------------------------|\n");
}
}};};
, 나는 "matrixNode"클래스의 여러 개체를 생성하고 함수에 전달했지만 작동하지 않습니다!
Matrix<int> matrix(5,6);
matrixNode<int> *matNode();
matNode->column=2;
matNode->line=0;
matNode->value=2;
matNode->PC=NULL;
matNode->PL=NULL;
matrixNode<int> *matNode2;
matNode2->column=5;
matNode2->line=5;
matNode2->value=5;
matNode2->PC=NULL;
matNode2->PL=NULL;
matrix.ceateSparsMatrix(matNode);
matrix.ceateSparsMatrix(matNode2);
개체를 잘 통과하지 못합니다. 도와주세요. 감사합니다.
"작동하지 않는다"는 것은 무엇을 의미합니까? –
두 개체를 함수에 전달해야하지만 첫 번째 개체 만 보냅니다. –
"첫 번째 물체를 보내려면"얼마나 멀리 있습니까? – Nimelrian