| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 783 人关注过本帖
标题:[求助]关于构造函数
只看楼主 加入收藏
27149
Rank: 1
等 级:新手上路
帖 子:39
专家分:0
注 册:2005-5-16
收藏
 问题点数:0 回复次数:1 
[求助]关于构造函数

// 11.cpp : Defines the entry point for the console application. //

#include "stdafx.h" #include "iostream.h" class point { public: point(double,double); private: double x,y; };

point::point(double tx,double ty) { x=tx; y=ty; cout<<"constructor is called:("<<x<<","<<y<<")"<<endl; }

int main(int argc, char* argv[]) { point p1(0.5.0.6); point p2(0.5,0.5663); return 0; } 这样做应该没错啊。 --------------------Configuration: 11 - Win32 Debug-------------------- Compiling... 11.cpp G:\c++工作区\11\11.cpp(23) : error C2143: syntax error : missing ')' before 'constant' G:\c++工作区\11\11.cpp(23) : error C2664: '__thiscall point::point(const class point &)' : cannot convert parameter 1 from 'const double' to 'const class point &' Reason: cannot convert from 'const double' to 'const class point' No constructor could take the source type, or constructor overload resolution was ambiguous G:\c++工作区\11\11.cpp(23) : error C2059: syntax error : ')' Error executing cl.exe.

11.obj - 3 error(s), 0 warning(s)

搜索更多相关主题的帖子: 函数 构造 
2005-06-21 05:10
shan183
Rank: 1
等 级:新手上路
帖 子:60
专家分:0
注 册:2005-5-30
收藏
得分:0 

#include <iostream> //库头文件要用< >,这样的搜索效率高

using namespace std;

class point { public: point(double,double); private: double x,y; };

point::point(double tx,double ty) { x=tx; y=ty; cout<<"Constructor is called:("<<x<<","<<y<<")"<<endl; }

int main() { point p1(0.5,0.6); //括号里的逗号被你写成点号了! point p2(0.5,0.5663);

return 0; }


挑战自己,超越自己,成就自己!

[此贴子已经被作者于2005-6-21 18:49:55编辑过]

2005-06-21 18:48
快速回复:[求助]关于构造函数
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.022382 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved