tags:

views:

48

answers:

1

My assignment is a Binary Search Tree derived from a Binary Tree, in my driver program this is how I've created a BST object. But I am slightly confused because I know there must be a constructor but no where in my assignment does it actually call for a constructor for the derived class.

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;

I'm having a hard time using these "pre" and "code" tags, the vector is actually vector<int> v; and the tree is really binSTree<int> t; With less than and greater signs around the int of course.

the error in my program is as follows:

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
+1  A: 

If the base class is default constructable, and the derived class does not make an explicit call to the base class constructor, the compiler inserts a call to the default base class constructor before calling the derived class constructor.

but that's got nothing to do with the error you are encountering, which is:

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

Remember, always always look at the first error your compiler produces, not the one at the bottom. This means you have, someplace in binSTree.h, on the first few lines, something like

#define ...

where the dots are something invalid.

TokenMacGuy
thankyou I will have to keep that in mind, I messed up my #ifndef ... #define ... statements thanks again!
rajh2504
@TokenMacGuy: Does that 'always always' rule apply for templates as well? I feel it gives more context if I scroll down to see where the error comes from during instantiaton.
Chubsdad
@Chubsdad: well, with templates, it's pretty much a crapshoot, but the reasoning is because the compiler should probably stop as soon as it encounters an error, because by definition, the compiler can't guess what you mean your code to do anymore. Some compilers try to parse past the error anyway, because they want to show you as much information about your code as possible.
TokenMacGuy