English 中文(简体)
C++派生类
原标题:C++ Derived Class
  • 时间:2010-10-22 01:04:26
  •  标签:
  • c++

我的作业是从二叉树派生的二叉搜索树,在我的驱动程序中,这就是我创建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<;整数>;v,并且该树实际上是binSTree<;整数>;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

请记住,始终始终查看编译器产生的第一个错误,而不是底部的错误。这意味着,在<code>binSTree.h</code>中的某个地方,在前几行,有类似于

#define ...

其中点是无效的东西。

问题回答

暂无回答




相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签