4 Replies - 740 Views - Last Post: 09 January 2009 - 03:04 PM Rate Topic: -----

#1 koki  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 79
  • Joined: 02-January 09

virtual function

Post icon  Posted 08 January 2009 - 12:27 PM

hey every body;
i want to ask if the virtual function can written out of the class.

because i try to implement it after the class but the compiler generate an error.......
Is This A Good Question/Topic? 0
  • +

Replies To: virtual function

#2 kapax  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 65
  • Joined: 02-July 08

Re: virtual function

Posted 08 January 2009 - 02:08 PM

You can, if you don't write a keyword 'virtual' when you are declaring it outside of the class. But I am not sure what consequences could you get after doing that. In my simple test app it worked fine and I do not see a reason why it should not.
Was This Post Helpful? 0
  • +
  • -

#3 KYA  Icon User is offline

  • Wubba lubba dub dub!
  • member icon

Reputation: 3202
  • View blog
  • Posts: 19,232
  • Joined: 14-September 07

Re: virtual function

Posted 08 January 2009 - 02:13 PM

If you could give more detail regarding your particular circumstance, i could give a more specific answer.

What purpose would a virtual function have outside of a class? The point of a virtual function is to tell sub classes they must override said function, etc...
Was This Post Helpful? 0
  • +
  • -

#4 kapax  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 65
  • Joined: 02-July 08

Re: virtual function

Posted 09 January 2009 - 10:01 AM

View PostKYA, on 8 Jan, 2009 - 01:13 PM, said:

If you could give more detail regarding your particular circumstance, i could give a more specific answer.

What purpose would a virtual function have outside of a class? The point of a virtual function is to tell sub classes they must override said function, etc...


I think he meant why it does not compile when he writes the function in ClassName::funcName() { } style.

By the way, since this topic is started, I am curious to know something. If I write the virtual function outside of a class the way I mentioned above (without "virtual" keyword), will it still be just a simple virtual function? Nothing unexpected will happen?
Was This Post Helpful? 0
  • +
  • -

#5 KYA  Icon User is offline

  • Wubba lubba dub dub!
  • member icon

Reputation: 3202
  • View blog
  • Posts: 19,232
  • Joined: 14-September 07

Re: virtual function

Posted 09 January 2009 - 03:04 PM

If you don't use the keyword, it isn't virtual. It would just be a function outside of a class.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1