【发布时间】:2013-03-16 06:39:03
【问题描述】:
我是c++ 的新手,我在构造函数和类方面遇到了困难。所以,这是我的头文件:
#pragma once
#include <string>
using namespace std;
class test
{
private:
string name;
int number;
public:
test();
test(string i,int b);
};
这是cpp文件:
#include "test.h"
#include <string>
using namespace std;
test::test(){}
test::test(string i,int b){
this->name=i;
this->number=b;
}
现在,当我尝试打电话时
test t=new test("rrr",8);
我明白了:
1 IntelliSense: no suitable constructor exists to convert from "test *" to "test"
那么,名称中包含 * 的类是怎么回事(例如,没有 .cpp 文件的类没有 asterix,所有其他类都有)?我做错了什么?
【问题讨论】:
标签: c++ object pointers constructor instance