Thread: problem with polymorphism

  1. #1
    Registered User
    Join Date
    Sep 2007
    Posts
    32

    problem with polymorphism

    Hi guys, I had created a base class and its derived class, and Both the base class have a virtual function, say hi(). The base class is pretty much pure. Now I declared a pointer of the the base class, and created a derived class object with the pointer. I tried to call hi(), but Visual C++ gave me some funny errors:


    d:\cryptography\crypter\crypter\crypter.cpp(149) : error C2248: 'BaseClass::Hi' : cannot access private member declared in class 'BaseClass'
    d:\cryptography\crypter\crypter\crypter.h(45) : see declaration of 'BaseClass::Hi'
    d:\cryptography\crypter\crypter\crypter.h(41) : see declaration of 'BaseClass

    can someone please help me?'

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Hi() needs to be public.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Sep 2007
    Posts
    32
    OMG thankyou! I was so dumb. Anyway, I get a new error: d:\cryptography\crypter\crypter\power.h(8) : error C2143: syntax error : missing ';' before 'using'

    and this is the bit where it points to.
    Code:
    #ifndef POWER_H
    #define POWER_H
    
    #include <iostream>
    #include <string>
    #include "Crypter.h"
    
    using std::cout;    // here it is
    using std::cin;
    using std::endl;
    using std::string;
    typedef unsigned short int USINT;

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    The problem is probably in Crypter.h, perhaps it is a missing semi-colon for a class declaration.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Sep 2007
    Posts
    32
    thanks alot guys, i did forget a semi-colon after a class declaration

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  2. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  3. Polymorphism Problem
    By ltanusaputra in forum C++ Programming
    Replies: 3
    Last Post: 04-25-2007, 11:36 AM
  4. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  5. Polymorphism - Can't Articulate Problem
    By Tonto in forum C++ Programming
    Replies: 17
    Last Post: 11-13-2006, 05:24 PM