HELP with template casting!!!!!!

This is a discussion on HELP with template casting!!!!!! within the C++ Programming forums, part of the General Programming Boards category; this code: http://pastebin.com/f168570c8 gives the compile error: test_templates.cpp: In function 'int main(int, char**)': test_templates.cpp:51: error: expected `(' before 'g' test_templates.cpp:51: ...

  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    1

    HELP with template casting!!!!!!

    this code: http://pastebin.com/f168570c8
    gives the compile error:
    test_templates.cpp: In function 'int main(int, char**)':
    test_templates.cpp:51: error: expected `(' before 'g'
    test_templates.cpp:51: error: expected `)' before ';' token
    test_templates.cpp:51: error: invalid const_cast from type 'bar<lab2::Gregorian>' to type 'bar<lab2::Julian>*'

    where the Julian and Gregorian are date classes that inherit from Date
    How do I "make" the variable j as if it was of <template> type Georgian?

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,892
    1) templ<Bar> is completely unrelated to templ<Foo>, even if Foo and Bar are in an inheritance relationship. There can be no conversion between the two that is not explicitly specified by the template.

    2) You cannot const_cast between different types. Only between cv-qualified versions of one type.

    3) You cannot cast an object to a pointer type. Especially not with const_cast.

    4) Casting between Gregorian and Julian calenders does not make sense. You can perhaps convert between them, but it would be a really bad idea to have the conversion implicit.

    5) C++ cast expressions (the *_cast<> things) need parentheses around the argument.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Specialising a member function with a template template parameter
    By the4thamigo_uk in forum C++ Programming
    Replies: 10
    Last Post: 10-12-2007, 04:37 AM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. error: template with C linkage
    By michaels-r in forum C++ Programming
    Replies: 3
    Last Post: 05-17-2006, 08:11 AM
  4. Class Template Trouble
    By pliang in forum C++ Programming
    Replies: 4
    Last Post: 04-21-2005, 04:15 AM
  5. oh me oh my hash maps up the wazoo
    By DarkDays in forum C++ Programming
    Replies: 5
    Last Post: 11-30-2001, 11:54 AM

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