如何使类论坛在 C++ 中使用字符串?

how can i make the class Forum work with strings in c++?

本文关键字:字符串 C++ 何使类 论坛      更新时间:2023-10-16

你好,我得到 [错误] 没有匹配函数调用"论坛::论坛(

常量字符 [5], 常量字符 [7], 整数, 整数, 整数字符 [6], 常量字符 [6], 整数, 常量字符 [6](' at 论坛f1=论坛("info","kostas",2005,2,220,"info1","nikos",2006,"hello"(;

!!我是面向对象编程的新手,所以我不知道如何使用字符串!这里发生了什么??谢谢!

#include<iostream>
#include<string>
using namespace std;
class Post{
int postNumber;
string title;
string creator;
int dateOfCreation;
string text;
public:
Post(int p=1,string t="first",string c="kostas",int da=2012, string te="text"){
postNumber=p;
title=t;
creator=c;
dateOfCreation=da;
text=te;
cout<<"I just created a post with"<<"Post number: "<<postNumber<<' '<<"Title: "<<title
<<title<<"with the name of creator: "<<creator<<"and date of creation: "<<dateOfCreation
<<text<<endl;
}
~Post(){
cout<<"Post number"<<postNumber<<"is about to be destroyed"<<endl;
}
void print(){
cout<<postNumber<<' '<<title<<' '<<creator<<' '<<dateOfCreation<<' '<<text<<endl;
}
};
class Thread{
std::string thema;
std::string creator;
int dateOfCreation;
int numberOfPost;
public:
Thread(string t="xrhisimes plhrofories",string c="kostas",int d=2015,int n=0){
thema=t;
creator=c;
dateOfCreation=d;
numberOfPost=n;
cout<<"I just created a Threat with"<<"thema: "<<thema<<' '
<<"name of creator: "<<creator<<' '<<"date of creation: "<<dateOfCreation<<' '
<<"and with number of post: "<<numberOfPost<<endl;
}
~Thread(){
cout<<"Theat with subject: "<<thema<<"is about to be destroyed "<<endl;
}
void print(){
cout<<thema<<' '<<creator<<' '<<dateOfCreation<<' '<<numberOfPost<<endl;
}
};
class Forum{
Post*post;
Thread*thread;
std::string subject;
public:
Forum(string s="antikeimenostrafis programmatismos"){
subject=s;
cout<<"Forum was just created with subject: "<<subject<<endl;
post=new Post;
thread= new Thread;
post->print();
thread->print();
}
Forum(string s,string th,string c,int d, int n,
int p, string t, string cr, int da, string te){
cout<<"Forum was just created with subject: "<<subject<<'n'<<endl;
post=new Post(p,t,cr,da,te);
thread=new Thread(th,c,d,n);
post->print();
thread->print();
}
};
int main(){
Forum f1=Forum("info","kostas",2005,2,220,"info1","nikos",2006,"hello");
return 0;
}

你的Forum构造函数与你试图给它的东西不匹配。 2strings,然后ints,而构造函数需要 3strings

Forum(string s,string th,string c...

仅仅是因为该函数调用中缺少字符串参数。Forum f1=Forum("info","kostas", <string missing here>, 2005,2,220,"info1","nikos",2006,"hello");