我会为这个问题疯狂.我正在尝试在c ++中使用list.我不能使用<vector>或<list>因为我的教授想要"纯粹的"c ++.(有了课,简而言之......).我可以创建只有一个int字段的列表,例如:
class List{
private:
struct node{
int *data;
node* next;
};
typedef struct node* nodePtr;
nodePtr head;
nodePtr curr;
nodePtr temp;
public:
List();
void AddNode(int addData);
void deleteNode(int delData);
void PrintList();
};
Run Code Online (Sandbox Code Playgroud)
(这是有效的,这不是整个代码,但它有效.)
现在出现的问题:我怎样才能创建一个对象列表,而不是列出"int"数据?
例如,如果我创建人员列表,如地址簿,我该怎么办?
我会发疯的,请帮助我.提前致谢.
(抱歉我的英语不好,我不是那么好:)
我有以下代码
#include <iostream>
#include<string>
#include <sstream>
using namespace std;
struct product{
int weight;
float price;
};
int main(){
string mystr;
product prod;
product *pointer;
pointer=∏
getline(cin,pointer->price);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
但它告诉我错误
没有重载函数的实例"getline"匹配参数列表
这是什么错误?
我是C#编码员.在C#中我们可以很容易地将通用对象传递给函数,但是C++没有对象的任何定义,这就是我想要做的:
void PrintToConsole(object msg)
{
gameconsole << msg;
}
Run Code Online (Sandbox Code Playgroud)
但遗憾的是,object在我尝试的C++中没有.
我的问题是,如何在不创建重载的情况下创建一个能够在其上使用任何对象的函数.
我是C++编程的学生我正在尝试用c ++创建一个年龄计算器,但我坚持将变量与另一个变量相乘这里是代码:
#include <iostream.h>
#include <conio.h>
void main()
{
clrscr();
int birthmonth,birthyear,birthdate;
int currentmonth,currentyear,currentdate;
int year,month,weeks,cal,calx,days,hours;
cout<<"Hassan's Age Calculator\n\n";
cout<<"Enter Your Birth Year(i.e:1996):";
cin>>birthyear;
cout<<"\nEnter Your Birth Month(i.e:10):";
cin>>birthmonth;
cout<<"\nEnter date of Birth(i.e:27):";
cin>>birthdate;
cout<<"\nEnter The Current Month(i.e:7):";
cin>>currentmonth;
cout<<"\nEnter The Current Year(i.e:2013):";
cin>>currentyear;
cout<<"\nEnter Current Date(i.e:24):";
cin>>currentdate;
year=currentyear-birthyear;
month=year*12;
weeks=month*4.34;
cal=(year*365.242)+currentdate;
calx=cal+30.43;
days=calx-birthdate;
hours=days*24;
cout<<"\n\n\t\tYour Age is "<<year<< " in Years" ;
cout<<"\n\n\t\tYour Age is "<<month<< " in Months" ;
cout<<"\n\n\t\tYour Age is "<<weeks<<" in weeks";
cout<<"\n\n\t\tYour Age is …Run Code Online (Sandbox Code Playgroud)