Abstract constructor

This is a discussion on Abstract constructor within the C++ Programming forums, part of the General Programming Boards category; Hi, I want to call an abstract function from the constructor of the abstract class. I am trying to implement ...

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    41

    Abstract constructor

    Hi,
    I want to call an abstract function from the constructor of the abstract class.

    I am trying to implement a C# code from :
    http://www.dofactory.com/Patterns/PatternFactory.aspx

    in C++. In C# I can call the an abstract function from constructor but in C++ it gives me the linking error.

    Can anyone please help...


    Best Regards,
    Shal

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,803
    Well, it would help for us to be able to see your C++ code.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,399
    Quote Originally Posted by Shal
    I want to call an abstract function from the constructor of the abstract class.
    You shouldn't ever call virtual functions from a constructor. It won't do what you want it to.
    http://www.artima.com/cppsource/nevercall.html
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

  4. #4
    Registered User
    Join Date
    May 2006
    Posts
    41
    Thanks a lot! Makes lot of sense not to call virtual functions in constructor. Wonder why C# does it!!

  5. #5
    Registered User
    Join Date
    May 2006
    Posts
    903
    C# is evil. C# is for newbs.










    Just kidding by the way..

  6. #6
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >C# is evil. C# is for newbs.
    Does that make newbs evil?
    My best code is written with the delete key.

  7. #7
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,740
    Hmm, don't think so. Because I could say "Nature is evil. Nature is for the birds," and birds still wouldn't be evil. ... Unless your afraid of birds and then I'm just plain wrong.

    So if you're afraid of newbs, they're evil.

  8. #8
    Registered User
    Join Date
    May 2006
    Posts
    903
    Yes. Indeed. Newbs are evil.

  9. #9
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >So if you're afraid of newbs, they're evil.
    I guess they're evil then. Newbs scare the bejezus out of me. After answering a few questions I have to curl up in the fetal position and cry for a few minutes before I have the strength to answer a few more.
    My best code is written with the delete key.

  10. #10
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    lol.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 06-10-2008, 08:38 PM
  2. C++ have a constructor call another constructor
    By QuestionC in forum C++ Programming
    Replies: 4
    Last Post: 05-17-2007, 01:59 AM
  3. Replies: 3
    Last Post: 03-25-2006, 11:59 PM
  4. abstract class
    By xddxogm3 in forum C++ Programming
    Replies: 5
    Last Post: 01-01-2005, 08:08 AM
  5. Need help in classes
    By LBY in forum C++ Programming
    Replies: 11
    Last Post: 11-26-2004, 03:50 AM

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