problem with polymorphism

This is a discussion on problem with polymorphism within the C++ Programming forums, part of the General Programming Boards category; Hi guys, I had created a base class and its derived class, and Both the base class have a virtual ...

  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
    21,890
    The problem is probably in Crypter.h, perhaps it is a missing semi-colon for a class declaration.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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, 04:24 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21