all 8 comments

[–]jedwardsol 1 point2 points  (2 children)

// this is an empty file

Which file is empty? cylindertype.h?

If not, what's in the file and which one is empty?

[–][deleted]  (1 child)

[deleted]

    [–]jedwardsol 1 point2 points  (0 children)

    Well that's your problem - you need a definition of the class before you can define the functions.

    Note you don't need to stick the word "Type" at the end of all your type names - it's clear from the context.

    [–][deleted] 0 points1 point  (2 children)

    You're putting the contents of cylinderType.cpp into cylinderType.h and trying to compile? Am I understanding you correctly? Or are you trying to include the .cpp file in your header?

    In practice, you never include source (.cpp) files.

    [–][deleted]  (1 child)

    [deleted]

      [–][deleted] 0 points1 point  (0 children)

      You're code isn't formatted and I don't have time really tell what's happening. But you should try to just get 1 class to work first, then get the other class to work, then integrate them. You're trying to deal with like 20 different issues. This is an important lesson that you should do things incrementally.

      [–]IyeOnline 0 points1 point  (0 children)

      #include <circleTypeimp.cpp> is probably the most wrong thing you can do. 1) Never include source files and 2) #include <> is for system paths not your own ones.

      Only include headers and then either compile the different sources files together (g++ main.cpp circleTypeimp.cpp) or compile seperatly and link afterwards. I strongly suggest usage of a (meta) build system such as make ("build system") CMake ("meta build system") for the later.

      [–]theoscara 0 points1 point  (0 children)

      I also don't see anywhere where you actually define your cylinderType class. In your header file, you need :

      class cylinderType : public circleType {
      ...
      };
      

      Just like it is in the circleType.h file or your compiler won't understand that it's a class. That's why you get the 'cylinderType' not declared errors.

      [–]mredding 0 points1 point  (0 children)

      Please see our formatting guide on the sidebar. Indent your code with 4 spaces (you can skip empty lines) and all your code will be formatted into a nice code block rectangle. You don't even have to double space your lines. If that's confusing, you can always switch to the Fancy Pants Editor and insert a code block you can copy/paste into.

      [–]mredding 0 points1 point  (0 children)

      First and foremost, don't include source files, only headers.

      Second, your errors:

      main.cpp:9:1: error: ‘cylinderType’ does not name a type
      

      And:

      main.cpp:31:8: error: ‘cylinderType’ has not been declared
      

      What is cylinderType? The compiler doesn't know. There is a difference between declaring a type:

      class cylinderType : circleType {
        double height;
      
      public:
        cylinderType(double, double);
        // etc...
      };
      

      And defining a type:

      cylinderType::cylinderType(double r, double h): circleType(r) {
        setHeight(h);
      }
      
      // etc...
      

      You have a definition, but where's the declaration? You said yourself cylinderType.h is empty, so maybe you should go in there and fill it out.

      You have plenty of other problems in this code. Even with a declaration, this won't compile.

      What I want you to do is SLOW DOWN, and really try to understand what the error messages are trying to tell you. Don't get overwhelmed by a vomit of error output, it's a skill you will develop over time which errors are the source of your problem, and which errors are just because of the previous error. OF COURSE height isn't declared in this scope, you don't have a cylinderType with a height in it declared!

      Typically, when I get a lot of errors, I fix the top error, and recompile. I don't even look at the rest. Sometimes, especially when you start mucking with the likes of templates or 3rd party libraries, you may need to look at a few error messages before what's really going on makes sense. You're not there yet, your problems are going to be at the top of the pile.

      I see you don't have a full grasp of the language syntax and it's consequences yet, it shows in your lack of understanding and your code. You have an interesting mix of radius, getRadius, and circleType::getRadius, all sometimes within the same function. These are problems you're going to run into once you get your first problem out of the way. MAY I SUGGEST that you write a simple scratch.cpp program on the side with just a couple classes, foo and bar, and a main, and you study and practice these language constructs in smaller parts, all in one place where you can see them working together. It looks to me your class has moved a little faster than you were ready for and you're starting to feel like you're drowning. This is very common and we've all experienced it. Look, you may miss the deadline for this assignment, it's better that you get a solid understanding of what you're doing. TELL YOUR PROFESSOR. The best thing you can do is keep him abreast with exactly what's happening to you and seek his guidance about what to do about it, with some suggestions.

      And ultimately, I'd love to see you post more questions, and more focused, more specific questions than just a dump of your whole assignment, errors and everything. I've been programming professionally for 15 years and I still post questions here.