由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - 为啥gcc找不到类的构造函数?
相关主题
[合集] 关于构造函数simple question on C++ initialization list
C++构造函数的问题构造函数里的异常处理
为什么在overloading中,friend <<不能读取private值呢?C++的"初始化"小结
c++ 得最基本问题why use static function here?
一个c++小问题问个overloading new operator的问题
string operator +question overloading ++ error
关于构造函数的一道测试题 (转载)请问关于overloading <<
请教c++数组初始化一个关于C++ template和overload的问题
相关话题的讨论汇总
话题: const话题: string话题: str话题: aa话题: gcc
进入Programming版参与讨论
1 (共1页)
k***n
发帖数: 20
1
class A {
private:
...
public:
A();
A(const char x, const char y);
A(const string& z);
...
}
int main () {
A aa;
const string str("AT");
aa(str);
return 0;
}
gcc编译提示:
no match for call to `(A) (const std::string&)'
我知道这个错误可能很低级,不吝求教。
S*********g
发帖数: 5298
2
你这个aa(str) call 的不是costructor
constructor是在
A aa;
这一行的时候执行的

【在 k***n 的大作中提到】
: class A {
: private:
: ...
: public:
: A();
: A(const char x, const char y);
: A(const string& z);
: ...
: }
: int main () {

k***n
发帖数: 20
3
哈,一句话点醒梦中人,多谢了!
e****d
发帖数: 333
4
你实际上在用 operator overloading
#include
#include
using namespace std;
class A{
string _str;
public:
A(){}
A(const string& z):_str(z){}
void operator()(const string& z){_str=z;}//(*)
string get() const{return _str;}
};
int main () {
A aa;
const string str("AT");
aa(str);
cout< }
(*)行返回值不是void的时候,基本就是functional object了。
1 (共1页)
进入Programming版参与讨论
相关主题
一个关于C++ template和overload的问题一个c++小问题
why copy assignment operator returns non-const type?string operator +
namespace 问题关于构造函数的一道测试题 (转载)
问个char*的问题请教c++数组初始化
[合集] 关于构造函数simple question on C++ initialization list
C++构造函数的问题构造函数里的异常处理
为什么在overloading中,friend <<不能读取private值呢?C++的"初始化"小结
c++ 得最基本问题why use static function here?
相关话题的讨论汇总
话题: const话题: string话题: str话题: aa话题: gcc