Thread: Getting a C2504 Error, why? (A derived class problem)

  1. #1
    Registered User
    Join Date
    Feb 2017
    Posts
    14

    Getting a C2504 Error, why? (A derived class problem)

    Hi all,

    I'm getting a C2504 error, (for those who don't know its a 'base class undefined' error) for what reason I do not know...

    beginning of my inherited polygon.h file:

    Code:
    class polygon : public isosceles
    {
    
    
    private:
    
    
        double sides;
    
    
    public:
    
    
        polygon(double length, double sides_val) : isosceles(length)
        {
            sides = sides_val;
        }
    my base class has only #include <cmath> and a definition of PI.

    any ideas?

    Thanks in advance.

  2. #2
    Guest
    Guest
    my base class has only #include <cmath> and a definition of PI.
    How does the definition of isosceles look like? You'll need that information to be known inside polygon.h.

    Btw, you can use initializer lists throughout, and don't need to invent different names for parameters and members – the compiler knows which one is which.
    Code:
    polygon(double length, double sides) : isosceles(length), sides(sides)
    { }

  3. #3
    Registered User
    Join Date
    Feb 2017
    Posts
    14
    Code:
    #pragma once
    #include <math.h>
    
    
    #define PI 3.14159265358979323846
    
    
    class isosceles
    {
    private:
    	double length;
    public:
    ^ start of isosceles

  4. #4
    Registered User
    Join Date
    Feb 2017
    Posts
    14
    I've put #include "isosceles.h" inside of polygon.h and it all seems to be compiling well now. Is this the proper way to do inherited classes i.e. to "#include" the base class within it?

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Quote Originally Posted by hewlettuser View Post
    I've put #include "isosceles.h" inside of polygon.h and it all seems to be compiling well now. Is this the proper way to do inherited classes i.e. to "#include" the base class within it?
    Yes.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    Registered User
    Join Date
    Feb 2017
    Posts
    14
    Thank you for all your help, again. :-)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 03-19-2008, 03:04 AM
  2. Getting "undeclared member" error with derived class
    By indigo0086 in forum C++ Programming
    Replies: 4
    Last Post: 10-07-2007, 06:41 AM
  3. Problem with class/derived class
    By ammochck21 in forum C++ Programming
    Replies: 2
    Last Post: 04-07-2007, 12:40 AM
  4. Derived class linking error
    By Enahs in forum C++ Programming
    Replies: 3
    Last Post: 11-12-2005, 10:18 PM
  5. Replies: 1
    Last Post: 12-11-2002, 10:31 PM

Tags for this Thread