Results 1 to 6 of 6

Thread: templates and self-references[resolved?]

  1. #1

    Thread Starter
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    templates and self-references[resolved?]

    Ok, I got a a template class. One of the parameters is again supposed to be a class that I write myself. Looks like this:
    Code:
    template<typename _C>
    class standard_config_formatter;
    
    template<typename _C, typename _Formatter = standard_config_formatter<_C> >
    class basic_configfile : public _Formatter
    // ...
    Then in the actual definition of the class standard_config_formatter I have this:

    Code:
    template<typename _C>
    class standard_config_formatter
    {
    private:
    	typedef basic_configfile<_C, standard_config_formatter<_C> > my_type;
    So I'm referencing standard_config_formatter from within standard_config_formatter. This seems to cause problems as VC++7 (6 would probably crash compiling this ) gives me an error whenever I try using this typedef:
    Code:
    	int get_int_prop(const my_type::string_type &name) {
    The error is:
    d:\work\daten\c++\fwrite\config.h(299) : error C2027: use of undefined type 'config_files::basic_configfile<_C,_Formatter>'
    with
    [
    _C=char,
    _Formatter=config_files::standard_config_formatter<char>
    ]
    which seems strange to be because standard_config_formatter is the undefined type, not basic_configfile.

    Anyone has an idea as to why this error occurs? I've got an idea to solve it, but it would take away some of the elegance of the code.

    edit: The idea worked.
    Last edited by CornedBee; Jan 27th, 2003 at 02:04 PM.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  2. #2

    Thread Starter
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Here are the whole files for anyone who is interested.
    Attached Files Attached Files
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    What was the idea?

    Your code looked a bit funky (parent class instantiating one of its own children? eek, tell me im dreaming!)

    =)

    Z.

  4. #4

    Thread Starter
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    The idea is to inject code into the class.
    And it's not instantiating it, it only has a reference.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  5. #5
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    *looks closer*
    puh, so it does...

    Z.

  6. #6

    Thread Starter
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594


    Ok, so it's not good OOP design. But it's IMO good C++ design
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width