在c ++中连接const和动态字符串

时间:2013-12-01 23:44:11

标签: c++ string

我有一个用于共轭动词的类,该类使用常量字符串和其他字符串来返回其结果,gcc正确构建它但在调用时遇到运行时错误

常量字符串类

ArabicHarakat.h

#pragma once
#include <string>

using namespace std;

namespace sarf{

class ArabicHarakat
{
public:

    static const wstring FATHA ;

    static const wstring DAMMA ;

    static const wstring KASRA ;

    static const wstring SKOON  ;

    static const wstring SHADDA ;

};

}

ArabicHarakat.cpp

#include "ArabicHarakat.h"

namespace sarf{


const wstring ArabicHarakat::FATHA = L"َ";

const wstring ArabicHarakat::DAMMA = L"ُ";

const wstring ArabicHarakat::KASRA = L"ِ";

const wstring ArabicHarakat::SKOON  = L"ْ";

const wstring ArabicHarakat::SHADDA = L"ّ";

}

我的类使用另一个名为root的类,它返回要在共轭中使用的字符串

和共轭动词的功能是:

wstring  AugmentedActivePastVerb::ConjugateInFormula8()
{
    return L"ت"+ArabicHarakat::FATHA+root->getC1()+ArabicHarakat::FATHA+root->getC2()+ArabicHarakat::SHADDA+ArabicHarakat::FATHA+root->getC3()+lastDpa+connectedPronoun;
}

所以,我有const字符串ArabicHarakat :: FATHA,L“XXX”等等和root.getCX()返回的动态字符串

上面的代码被正确编译,但在运行时我得到Segmentation fault error

我希望你能提供帮助 提前谢谢

从codeblocks调用堆栈

#0 ??   sarf::verb::trilateral::augmented::AugmentedActivePastVerb::ConjugateInFormula8 (this=0x69d580) (/home/yasser/projects/testv3z_augmented/verb/trilateral/augmented/active/AugmentedActivePastVerb.cpp:63)
#1 0x408ba3 sarf::verb::trilateral::augmented::AugmentedActivePastVerb::AugmentedActivePastVerb(this=0x69d580, r=0x6928e0, lDpa=..., cp=..., fn=7) (/home/yasser/projects/testv3z_augmented/verb/trilateral/augmented/active/AugmentedActivePastVerb.cpp:30)
#2 0x407214 sarf::verb::trilateral::augmented::AugmentedActivePastConjugator::createVerb(this=0x7fffffffe1af, root=0x6928e0, pronounIndex=0, formulaNo=7) (/home/yasser/projects/testv3z_augmented/verb/trilateral/augmented/active/AugmentedActivePastConjugator.cpp:27)
#3 0x40730a sarf::verb::trilateral::augmented::AugmentedActivePastConjugator::createVerbList(this=0x7fffffffe1af, root=0x6928e0, formulaNo=7) (/home/yasser/projects/testv3z_augmented/verb/trilateral/augmented/active/AugmentedActivePastConjugator.cpp:34)
#4 0x403295 testverb1() (/home/yasser/projects/testv3z_augmented/main.cpp:61)
#5 0x4034a8 main() (/home/yasser/projects/testv3z_augmented/main.cpp:83)

这是基类,它是一个调用ConjugateInFormulaX()函数的抽象类 .h

#pragma once

#include <string>
#include "AugmentedTrilateralRoot.h"

using namespace std;

namespace sarf
{
    namespace verb
    {
        namespace trilateral
        {
            namespace augmented
            {

                class AugmentedPastVerb
                {
                        typedef wstring (AugmentedPastVerb::*ConjugateFuns)();

                    protected:
                        AugmentedTrilateralRoot* root;

                        wstring resualt;

                        wstring lastDpa;

                        wstring connectedPronoun;

                        virtual wstring ConjugateInFormula1()=0;

                        virtual wstring ConjugateInFormula2()=0;

                        virtual wstring ConjugateInFormula3()=0;

                        virtual wstring ConjugateInFormula4()=0;

                        virtual wstring ConjugateInFormula5()=0;

                        virtual wstring ConjugateInFormula6()=0;

                        virtual wstring ConjugateInFormula7()=0;

                        virtual wstring ConjugateInFormula8()=0;

                        virtual wstring ConjugateInFormula9()=0;

                        virtual wstring ConjugateInFormula10()=0;

                        virtual wstring ConjugateInFormula12()=0;

                        ConjugateFuns ConjugateFunsList[12];

                    public:
                        AugmentedPastVerb() {}
                        AugmentedPastVerb(AugmentedTrilateralRoot* r, wstring lDpa, wstring cp,int fn);

                        inline wstring getConnectedPronoun()
                        {
                            return connectedPronoun;
                        }
                        inline AugmentedTrilateralRoot* getRoot()
                        {
                            return root;
                        }

                        inline wstring getLastDpa()
                        {
                            return lastDpa;
                        }

                        inline wstring toString()
                        {
                            return AugmentedPastVerb::resualt;
                        }
                };

            }
        }
    }
}

的.cpp

#include "AugmentedPastVerb.h"


    using namespace std;

namespace sarf {namespace verb{namespace trilateral{namespace augmented{

     AugmentedPastVerb::AugmentedPastVerb(AugmentedTrilateralRoot* r, wstring lDpa, wstring cp,int fn)
     {
        ConjugateFunsList[0] = &AugmentedPastVerb::ConjugateInFormula1;
        ConjugateFunsList[1] = &AugmentedPastVerb::ConjugateInFormula2;
        ConjugateFunsList[2] = &AugmentedPastVerb::ConjugateInFormula3;
        ConjugateFunsList[3] = &AugmentedPastVerb::ConjugateInFormula4;
        ConjugateFunsList[4] = &AugmentedPastVerb::ConjugateInFormula5;
        ConjugateFunsList[5] = &AugmentedPastVerb::ConjugateInFormula6;
        ConjugateFunsList[6] = &AugmentedPastVerb::ConjugateInFormula7;
        ConjugateFunsList[7] = &AugmentedPastVerb::ConjugateInFormula8;
        ConjugateFunsList[8] = &AugmentedPastVerb::ConjugateInFormula9;
        ConjugateFunsList[9] = &AugmentedPastVerb::ConjugateInFormula10;
        ConjugateFunsList[10] = &AugmentedPastVerb::ConjugateInFormula11;
        ConjugateFunsList[11] = &AugmentedPastVerb::ConjugateInFormula12;

        root = r;
        lastDpa = lDpa;
        connectedPronoun = cp;
        //resualt = (this->*ConjugateFunsList[formulaNo])();
     }
}}}}

这个类让root被绑定 .H

#pragma once

#include <vector>
#include <string>
#include "AugmentationFormula.h"
#include "TrilateralRoot.h"

    using namespace std;
    using namespace sarf;

namespace sarf {namespace verb{namespace trilateral{namespace augmented{

class AugmentedTrilateralRoot : public TrilateralRoot{
private:
    wstring c1;
    wstring c2;
    wstring c3;

    vector<AugmentationFormula*> augmentations;

public:
    AugmentedTrilateralRoot(){}

    void addAugmentationFormula(AugmentationFormula* formula);

    virtual wstring getC1();
    virtual wstring getC2() ;
    virtual wstring getC3();

    vector<AugmentationFormula*> getAugmentationList();
    AugmentationFormula* getAugmentationFormula(int formulaNo) ;

    void setC1(wstring c1v) ;
    void setC2(wstring c2v);
    void setC3(wstring c3v) ;

};

}}}}

的.cpp

#include "AugmentedTrilateralRoot.h"

using namespace std;

namespace sarf {namespace verb{namespace trilateral{namespace augmented{

    void AugmentedTrilateralRoot::addAugmentationFormula(AugmentationFormula* formula) {
        augmentations.push_back(formula);
    }

    wstring AugmentedTrilateralRoot::getC1() { return c1; }

    wstring AugmentedTrilateralRoot::getC2() { return c2; }

    wstring AugmentedTrilateralRoot::getC3() { return c3; }

    vector<AugmentationFormula*> AugmentedTrilateralRoot::getAugmentationList() {
        return augmentations;
    }

    AugmentationFormula* AugmentedTrilateralRoot::getAugmentationFormula(int formulaNo) {
        return augmentations[formulaNo];
    }

     void AugmentedTrilateralRoot::setC3(wstring c3v) {c3 = c3v;}

     void AugmentedTrilateralRoot::setC2(wstring c2v) {c2 = c2v;}

     void AugmentedTrilateralRoot::setC1(wstring c1v) {c1 = c1v;}

}}}}

0 个答案:

没有答案