主函数中引用的未解析的外部符号错误

时间:2016-03-23 00:25:24

标签: c++ compiler-errors

我正在处理的项目中有一个Strings.h,一个Strings.cpp和一个main.cpp函数。编译器目前给我以下错误,我不明白为什么。

  

错误LNK2019未解析的外部符号“public:void __thiscall   Strings :: getType(class std :: basic_string,class std :: allocator>)“   (?的getType @ @@字符串QAEXV?$ basic_string的@ DU?$ char_traits @ d @ @@ STD V'$分配器@ d @ @@ 2 STD @@@ Z)   在函数_main Project12 c:\ Users \ dan中引用   revie \ documents \ visual studio 2015 \ Projects \ Project12 \ main.obj

Strings.h

#ifndef STRINGS_H
#define STRINGS_H
#include <vector>
#include <string>

using namespace std;

//enum stringType { NONE = 0, SINGLEWORD = 1, PALINDROME, WITHDIGITS, OTHERS }; // 1.1

class Strings {

public:
    // public members


    void getType(string phrase); // 1.4
    int getSize(string phrase); // 1.4


    //void checkValid();



private:
    // private members
    string phrase; // 1.2
    int stringSize; // 1.3

    vector<Strings> String_records; //2.1
};

#endif

Strings.cpp

#include "Strings.h"
#include <iostream>



void Strings::getType(string phrase)
{
    cout << "Hello";
    vector <char> palin1;
    vector <char> palin2;
    bool palinSwitch = true;
    // Palindrone Test

    // forward
    for (unsigned int i = 0; i < phrase.size(); ++i)
    {
        palin1.push_back(phrase[i]); 
    }

    // backward
    for (unsigned int i = phrase.size(); i >= 0; --i)
    {
        palin2.push_back(phrase[i]);
    }

    // Comparison for palindrone
    for (unsigned int i = 0; i < phrase.size(); ++i)
    {
        if (palin1[i] != palin2[i])
        {
            cout << "This is not a palindrone" << endl;
            palinSwitch = false;
        }
    }

    if (palinSwitch == false)
    {
        bool phraseSwitch = false;
        for (unsigned int i = 0; i < phrase.size(); ++i)
        {
            // PHRASE CASE-----------------------------------------------------
            if (isspace(phrase[i]))
            {
                // it is a phrase
                for (unsigned int i = 0; i < phrase.size(); ++i)
                {
                    if (isdigit(phrase[i]))
                    {
                        phraseSwitch = true;
                    }
                }

                if (phraseSwitch == true)
                {
                    cout << "This is a phrase with digits" << endl;
                }
                else if (phraseSwitch == false)
                {
                    cout << "This is a phrase without digits" << endl;
                }
            }
            // SINGLE WORD CASE------------------------------------------------
            else // it is a single word
            {
                for (unsigned int i = 0; i < phrase.size(); ++i)
                {
                    if (isdigit(phrase[i]))
                        phraseSwitch = true;
                }
                if (phraseSwitch == true)
                {
                    cout << "This is one word with digits" << endl;
                }
                else if (phraseSwitch == false)
                {
                    cout << "This is one word without digits" << endl;
                }
            }

        }
    }
}

int Strings::getSize(string phrase)
{
    int count = 0;
    for (unsigned int i = 0; i < phrase.size(); ++i)
    {
        if (!isspace(phrase[i]))
            ++count;
    }
    return count;
}

的main.cpp

#include "Strings.h"
#include <iostream>

int main()
{
    string phrase;

    Strings s; 

    cout << "Please enter a string to be analyzed: "; 
    cin >> phrase; 

    s.getType(phrase);
    //s.getSize(phrase);

    return 0;
}

如果有人能够阐明这一点,我们将不胜感激。

0 个答案:

没有答案