2012-07-29 80 views
0

目標:從具有2個模板參數的類繼承。從具有多個參數的模板類繼承時出錯

錯誤

錯誤錯誤C2143:語法錯誤:之前 '<'

守則失蹤 ''

template< typename Type > 
class AssetManager : public IsDerivedFromBase< Type, Asset* > 
{ 
    // Class specific code here 
}; 

你需要的東西知道:資產是一個類,只是用一個吸氣劑/設置器包裝char*IsDerivedFromBase將用於基本上測試TypeAsset的衍生物。這些類的集合被隔離在自己的小型Visual Studio 2012項目中,並且一旦所有功能都已經過徹底測試,它們將被集成到主項目中。

基於評論

進行一些編輯謝謝你的幫助迄今爲止,我真的很感激。這裏有一些更多的細節:

IsDerivedFromBase.h

#ifndef ISDERIVEDFROMBASE_H 
#define ISDERIVEDFROMBASE_H 

#include<iostream> // For access to NULL 

namespace Fenrir 
{ 
    template< typename Type, typename Base > 
    class IsDerivedFromBase 
    { 
    private: 
     static void Constraints(Type* _inheritedType) 
     { 
      Base* temp = NULL; 

      // Should throw compiler error if 
      // this assignment is not possible. 
      temp = _inheritedType; 
     } 

    protected: 
     IsDerivedFromBase() { void(*test)(Type*) = Constraints; } 
    }; 
} 

#endif 

:這個類是基於關I類的一篇文章中讀到的。我從那以後找到了一個更好的方法來達到預期的結果;然而,我想了解這個錯誤源於何處。

AssetManager.h」

#ifndef ASSETMANAGER_H 
#define ASSETMANAGER_H 

#include "IsDerivedFromBase.h" 

namespace Fenrir 
{ 
    template< typename Type > 
    class AssetManager : public IsDerivedFromBase< Type, Asset* > 
    { 
     // Class specific code 
    }; 
} 

#endif 

保持類的特定代碼到最低限度,以保持這個帖子整齊越好,如果需要更多的信息只是讓我知道,我可以將它添加:)。

+1

什麼是'IsDerivedFromBase'聲明? – ulidtko 2012-07-29 22:05:30

+5

提供一個獨立的,最小的示例,展示該問題。 – 2012-07-29 22:06:07

+0

似乎編譯器不知道IsDerivedFromBase類,或者關於它是模板類。無論如何,還有其他錯誤,編譯器給你。看看他們。 – ForEveR 2012-07-29 22:07:34

回答

0

解決了我的問題,這有趣的是愚蠢的。所以由於評論(來自Jesse Good)我快速瀏覽了我的包裝。由於這是一個小型的「快速啓動」類型的項目,我沒有真正關注它們。我不知道確切的錯誤發生在哪裏,但我發現AssetManager不知道IsDerivedFromBase所以我建立了以下代碼塊來解決這個問題,而不必編寫一堆 #包括聲明無處不在!

// Contact point houses all of the include files 
// for this project to keep everything in one place. 

#ifndef CONTACTPOINT_H 
#define CONTACTPOINT_H 

#include "Asset.h" 
#include "Sprite.h" 
#include "IsDerivedFromBase.h" 
#include "GenericManager.h" 
#include "AssetManager.h" 

#endif 

現在我只是把它包括在每個標題中,一切都很好。一年多來我一直在編程C++,並且從未遇到過這個問題,這是一個很好的教訓,可以爲任何新的編程學習。

感謝您的幫助大家:)

0

該錯誤信息是常見的,當編譯器遇到它,沒想到一個標識符,那麼第一個猜測是,IsDerivedFromBase不是當時已知編譯器(也許你沒有包含適當的標題?)。或者,如果IsDerivedFromBase不是模板,則編譯器也會在其後面預計爲,(或;)。