ほぼどんな長さの数でも計算できる電卓を作りたいです。
私が必要とした最初の関数は、文字列をリンクリストに変換してから、リストの先頭へのポインタを返す関数です。
ただし、コンパイル時にエラーが発生します:エラーC2352:'main :: StringToList':非静的メンバーの不正な呼び出し。行:7;
main.cppファイルとmain.hファイルを提供します。
よろしくお願いします
main.cpp
#include "main.h"
int main()
{
main::node *head = main::StringToList("123");
main::node *temp = new main::node;
temp = head;
while (temp->next != NULL)
{
cout << temp->data;
temp = temp->next;
}
std::cout << "\nThe program has completed successfully\n\n";
system("PAUSE");
return 0;
}
main::node * StringToList(string number)
{
int loopTimes = number.length() - 1;
int looper = 0;
int *i = new int;
i = &looper;
main::node *temp = new main::node;
main::node *head;
head = temp;
for ( i = &loopTimes ; *i >= 0; *i = *i - 1)
{
temp->data = number[*i] - 48;
main::node *temp2 = new main::node;
temp->next = temp2;
temp = temp2;
}
temp->next = NULL;
return head;
}
main.h
#ifndef MAIN_H
#define MAIN_H
#include <iostream>
#include <string>
using namespace std;
class main
{
public:
typedef struct node
{
int data;
node *next;
};
node* StringToList (string number);
};
#endif