でC++を使用してオブジェクトファイルの機能を使用する:私はバイナリ検索ツリーを作っていると私は、.cppファイルに次の機能を持っているBST
void MovieTree::printMovieInventory(MovieNode* node)
{
if(node)
{
while(node->rightChild && node->leftChild)
{
std::cout<<"Movie:"<<node->title<<" "<<node->quantity<<std::endl;
if(node->rightChild)
{
printMovieInventory(node->rightChild);
}
if(node->leftChild)
{
printMovieInventory(node->leftChild);
}
}
}
else
{
std::cout<<"No movies in list!"<<std::endl;
}
私はどのように私がすべきに、わずかわかりませんよ私のmain.cppファイルまたは "ドライバファイル"でこの関数を参照している可能性があります。私はこれを使用して、メインでそれに言及:
case 3: //message is read in from file
{
MovieTree::printMovieInventory(node);
}
break;
しかし、これを参照する時には、それだけでエラーがスローされます。
Driver.cpp:37:40: error: cannot call member function 'void MovieTree::printMovieInventory(MovieNode*) without object
MovieTree::printMovieInventory(node);
ないこれが何を意味するのか確認を。
ここでの主なフル:
int main(int argc, char **argv)
{
bool quit = false;
string s_input;
int input;
// loop until the user quits
while (!quit)
{
MovieNode* node = new MovieNode;
printOptions();
// read in input, assuming a number comes in
getline(cin, s_input);
input = stoi(s_input);
switch (input)
{
// print all nodes
case 1: //rebuild network
break;
break;
case 3: //message is read in from file
{
MovieTree::printMovieInventory(node);
}
break;
case 4: // quit
quit = true;
cout << "Goodbye!"<< endl;
break;
default: // invalid input
cout << "Invalid Input" << endl;
break;
}
}
}
実際にはどうなりますか? –
'MovieTree'のインスタンスが必要で、そのインスタンスで関数を呼び出します。それがオブジェクト指向プログラミングと呼ばれる理由です。 – NathanOliver
@πάντα_ῥεMovie MovieTreeのインスタンスを参照しようとすると、エラーが発生します – Whatamia