Explicit and Virtual, just out of curiosity

This is a discussion on Explicit and Virtual, just out of curiosity within the C++ Programming forums, part of the General Programming Boards category; One of the things I like in C/C++ is that... it makes sense. For the most part (mind you the ...

  1. #1
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,469

    Explicit and Virtual, just out of curiosity

    One of the things I like in C/C++ is that... it makes sense. For the most part (mind you the disclaimer) keywords and language constructs are obvious in the way they are used and why they are used in that particular way.

    I don't actually expect an answer to this question. Probably there isn't one. But I grew accustomed to believe that almost everything in C/C++ is done in a certain way for a very good reason. And so here it is one of the things that has been nagging me for a long time:

    Why can't we use virtual and explicit also on function definitions, but only on their declarations? Really, now....
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,319
    Have you read The Design and Evolution of C++ by Stroustrup?

  3. #3
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,469
    Nope. No access to the book as of yet. I've spent a few hundred dollars in books already. A very... damaging effort, I should say. The last, just a couple of days ago in a duty-free bookshop in Heathrow airport (Josuttis' C++ Standard Library). But confessedly, that book is not in my list of priorities for the moment
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    7,319
    I don't know if the answer is in there, but the two places I would check would be that book and a search of comp.lang.c++.moderated.

  5. #5
    Cat
    Cat is offline
    Registered User
    Join Date
    May 2003
    Posts
    1,571
    Hmm. I believe that it is because only keywords which modify the signature of the function itself are allowed (and required) at the definition.

    It would be illegal to have two functions which differed only by virtual/nonvirtual, for example. It's not illegal to have functions which differ, for example, only by const:

    Code:
    class x{
        void function() const{
            std::cout << "Const!" << std::endl;
        }
        void function() {
            std::cout << "Not Const!" << std::endl;
        }
    };
    You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need Partners (D&D fan preferably)
    By C_ntua in forum Game Programming
    Replies: 44
    Last Post: 11-22-2008, 08:21 AM
  2. Replies: 39
    Last Post: 11-30-2007, 01:16 AM
  3. Stroustrup Talk on C++0x
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 19
    Last Post: 07-20-2007, 02:02 AM
  4. Exception handling framework based on multiple inheritance
    By Mario F. in forum C++ Programming
    Replies: 11
    Last Post: 06-25-2007, 10:17 AM

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