簡體   English   中英

C ++派生類

[英]C++ Derived Class

我的任務是從二進制樹派生一個二進制搜索樹,在我的驅動程序中,這就是我創建BST對象的方式。 但是我有點困惑,因為我知道必須有一個構造函數,但是在我的分配中,它實際上並不需要為派生類構造函數。

int main() {
   int x = 0;
   int n = 0;
   int len = 0;
   int total = 0;
   int seed = 0;
   bool y;
   cin >> n;

   vector<int> v;
   binSTree<int> t;

我很難使用這些“ pre”和“ code”標簽,向量實際上是vector<int> v; 樹真的是binSTree<int> t; 當然,int周圍的符號越來越少。

我的程序中的錯誤如下:

In file included from prog6.cc:2:
    binSTree.h:1:9: error: macro names must be identifiers
prog6.cc: In function ‘int main()’:
prog6.cc:16: error: ‘binSTree’ was not declared in this scope

如果基類是默認可構造的,並且派生類未對基類構造函數進行顯式調用,則編譯器將在調用派生類構造函數之前插入對默認基類構造函數的調用。

但這與您遇到的錯誤無關,即:

In file included from prog6.cc:2:
    binSTree.h:1:9: error: macro names must be identifiers

請記住,請始終查看編譯器產生的第一個錯誤,而不是底部的錯誤。 這意味着您在前幾行中的binSTree.h中有一個類似

#define ...

點是無效的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM