错误C2819:类型'Robot :: Animation'没有重载成员'运算符 - >'

时间:2010-11-22 06:11:22

标签: c++ visual-studio-2008 ogre3d

我不能为它找到为什么这会引发错误!好的,所以我有一个包含一些对象的Struct。然后我创建一个指向该结构的指针并逐个设置项目。我不断收到错误。这是代码:

Robot.h:

// Name and Animation info
std::map<std::string, Ogre::AnimationState*> mAnims2;

struct Animation {
    std::string name;   // The name of the animation state
    Ogre::AnimationState* mAnimState;   // The actual animation state
    bool FADE_IN;       // Fade the animation in
    bool FADE_OUT;      // Fade the animation out
};

Robot.cpp:

    // Go through the set by using iterator
while (animStateIter.hasMoreElements()) {
    // The Animation object we will construct
    Animation* mAnimation = new Animation();
    // Initial values for Fading In and Out
    mAnimation->FADE_IN = false;    
    mAnimation->FADE_OUT = false;   
    // Create the Animation object, using the next animation in the list
    mAnimation->mAnimState = animStateIter.getNext();
    // Set the animations name
    mAnimation->name = Animation->mAnimState->getAnimationName();
    // Make sure the animation is set to Loop
    mAnimation->mAnimState->setLoop( true );
    // Insert the Animation object into the list of Animations
    mAnims2.insert( std::make_pair( mAnimation->name, mAnimation) );
    /* DEBUG */
    output << mAnimation->name << std::endl;
}

错误:

Error 1 error C2819: type 'Robot::Animation' does not have an overloaded member 'operator ->' c:\users\masry\school-work\fall-2010\cs-425\homework-4\gameengine_solution\robot.cpp 52

另外,如果您注意到,我正在尝试动态创建Struct对象并将它们插入到Map中。我打电话给:

Animation* mAnimation = new Animation();

在一个while循环中,这是一个很好的OO设计吗?如果没有,有什么更好的方法?谢谢。

修改 所以,多亏了Frédéric,原来我错过了一封信。但现在我收到一个错误说:

Error   17  error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,unsigned char)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::string'    c:\users\masry\school-work\fall-2010\cs-425\homework-4\gameengine_solution\robot.cpp    58

1 个答案:

答案 0 :(得分:2)

我认为你的错误就在那里:

// Set the animations name
mAnimation->name = Animation->mAnimState->getAnimationName();

那应该是:

// Set the animations name
mAnimation->name = mAnimation->mAnimState->getAnimationName();