小编Hay*_*den的帖子

为什么C++不允许我使用字符串作为类中的数据成员?

所以我在名为Classes.h的头文件中有以下代码:

#ifndef CLASSESS_H
#define CLASSESS_H

class PalindromeCheck
{
private:
    string strToCheck;
    string copy;

public:
    PalindromeCheck(string testSubject) : strToCheck(testSubject) {} //Constructor

    void Check()
    {
        copy = strToCheck; //Copy strToCheck into copy so that once strToCheck has been reversed, it has something to be checked against.
        reverse(strToCheck.begin(), strToCheck.end());  //Reverse the string so that it can be checked to see if it is a palindrome.

        if (strToCheck == copy) 
        {
            cout << "The string is a palindrome" << endl;
            return;
        }
        else 
        { …
Run Code Online (Sandbox Code Playgroud)

c++ string stl class

-2
推荐指数
1
解决办法
676
查看次数

如果我有一个调用其他实例之一的重载函数,它是否被认为是一个递归函数?

这是假设,但我有一个带有两个重载构造函数的类 - 其中没有一个是默认的构造函数.如果我从另一个调用一个构造函数,它会递归吗?例:

class Example
{
     Example(const int integer)
     {
          //Constructor Code Here
     }

     Example(argument)
     {
          Example object(68);
          //Rest of constructor code
     }
};
Run Code Online (Sandbox Code Playgroud)

c++ recursion constructor class function-calls

-4
推荐指数
1
解决办法
97
查看次数

标签 统计

c++ ×2

class ×2

constructor ×1

function-calls ×1

recursion ×1

stl ×1

string ×1