我是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,所有其他人都可以)?我做错了什么?
不错,你的答案比我的好多了:) +1 – 2013-03-26 13:01:30
tnx很多。你猜对了,我在java和c#编程,所以我有点努力与c + + :) – klo 2013-03-26 13:08:25
@klo如果你尝试编程C++就像你编程的Java,你会犯大量的错误。他们根本不是很相似。 – john 2013-03-26 13:26:45