compiling x and error in y templated inheritance

This is a discussion on compiling x and error in y templated inheritance within the C++ Programming forums, part of the General Programming Boards category; I've a class paramsMapCore Code: template <typename KeyType, typename ValueType> class paramsMapCore : public std::map<KeyType, ValueType>{ ... } and another ...

  1. #1
    Registered User
    Join Date
    Jun 2007
    Posts
    219

    compiling x and error in y templated inheritance

    I've a class paramsMapCore
    Code:
    template <typename KeyType, typename ValueType>
    class paramsMapCore : public std::map<KeyType, ValueType>{
      ...
    }
    and another Class paramsMap
    Code:
    class paramsMap : public paramsMapCore<string, Var>{
      ...
    }
    All these Classes compiles and works nice.

    I just another Class Js::Object
    Which is in Js namespace.
    Code:
    class Object: public Js::JVar, public paramsMapCore<string, Js::JVar>{
      ...
    }
    when it compiles object.cpp it doesn't fires any error on object.cpp or object.h
    but it shows some error comming from paramsmap.h and paramsmap.hpp

    wondering cause If I remove the Js::Object class everything including the paramsMap and paramsMapCore works fine.

    This is the error message
    Code:
    compiling object.cpp (g++)
    cgi++/paramsmap.h:36: error: expected template-name before '<' token
    cgi++/paramsmap.h:36: error: expected `{' before '<' token
    cgi++/paramsmap.h:36: error: expected unqualified-id before '<' token
    cgi++/object.cpp:34: instantiated from here
    cgi++/paramsmapcore.hpp:38: error: conversion from 'Var' to non-scalar type 'Js::JVar' requested
    and another thing that makes me pull my hair is I've included paramsmapcore.h from object.h but I've never included paramsmap.h from object.h so why its bothering about paramsmap.h

    Not getting any clue to solve plese help
    Last edited by noobcpp; 10-19-2008 at 01:18 PM.

  2. #2
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,667
    Not only moderators can help, you know...
    Anyway, the thing is that templates are only parsed and evaluated once they're instantiated. If you don't instantiate them, the compiler will basically ignore them.
    So you may "think" that your class is fine, but in reality it may be not.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User
    Join Date
    Apr 2006
    Posts
    2,046
    You can't inherent from std::map; it doesn't use virtual functions that are needed for inheritance. But thats not the cause of your errors.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  4. #4
    Registered User
    Join Date
    Jun 2007
    Posts
    219
    So Whats the cause of the error ??

    inheriting from std::map can be discussed in a separate topic

  5. #5
    Registered User
    Join Date
    Jun 2007
    Posts
    219
    Here goes all my source codes with #include directivrs

    object.h
    Code:
    #ifndef JSOBJECT_H
    #define JSOBJECT_H
    
    #include "jvar.h"
    #include "paramsmapcore.h"
    #include <sstream>
    #include <string>
    
    using std::string;
    using std::stringstream;
    
    namespace Js{
    
    class Object: public Js::JVar, public paramsMapCore<string, Js::JVar>{
      public:
        Object();
        ~Object();
    };
    
    }
    
    #endif
    object.cpp
    Code:
    #include "object.h"
    
    namespace Js {
    
    Object::Object(): Js::JVar(), paramsMapCore<string, Js::JVar>(){
    
    }
    
    
    Object::~Object(){
    
    }
    
    
    }
    paramsmapcore.h
    Code:
    #ifndef PARAMSMAPCORE_H
    #define PARAMSMAPCORE_H
    
    #include <map>
    #include <string>
    #include "var.h"
    
    class Var;
    
    template <typename KeyType, typename ValueType>
    class paramsMapCore : public std::map<KeyType, ValueType>{
      public:
        paramsMapCore();
        ~paramsMapCore();
      public:
        bool exists(const KeyType& key) const;
        virtual ValueType get(const KeyType& key) const;
        virtual void set(const KeyType& key, const ValueType& val);
        bool remove(const KeyType& key);
        void removeAll();
        typename paramsMapCore<KeyType, ValueType>::iterator search(const KeyType& key);
        typename paramsMapCore<KeyType, ValueType>::const_iterator search(const KeyType& key) const;
        typename paramsMapCore<KeyType, ValueType>::iterator each();
        typename paramsMapCore<KeyType, ValueType>::const_iterator each() const;
    };
    #include "paramsmapcore.hpp"
    #endif

    paramsmap.h
    Code:
    #ifndef PARAMSMAP_H
    #define PARAMSMAP_H
    
    #include <string>
    #include <map>
    #include "var.h"
    #include "paramsmapcore.h"
    
    using std::string;
    using std::map;
    
    class Var;
    
    class paramsMap : public paramsMapCore<string, Var>{
      public:
        paramsMap();
        ~paramsMap();
    };
    
    #endif

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,794
    It seems that the error lies in or is related to jvar.h, var.h and/or paramsmapcore.hpp. I commented out those #include lines and made Js::JVar an empty struct and there was no errors when compiling with the MinGW port of g++ 3.4.5. There were warnings related to having virtual functions with a non-virtual destructor (i.e., you should be declaring paramsMapCore's destructor virtual, and you should not be publicly deriving from std::map to begin with).
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    Registered User
    Join Date
    Jun 2007
    Posts
    219
    I dont find anything wrong in Js::JVar.

    jvar.h
    Code:
    namespace Js {
    
    class JVar{
      public:
        JVar();
        virtual ~JVar();
    };
    
    }
    and this is jvar.cpp
    Code:
    namespace Js {
    
    JVar::JVar(){
    
    }
    
    
    JVar::~JVar(){
    
    }
    
    
    }

  8. #8
    Registered User
    Join Date
    Jun 2007
    Posts
    219
    stuck in this problem for several days nobody can help me ??
    I am scared..

Popular pages Recent additions subscribe to a feed

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