读书人

新手 这个程序死活通过不了

发布时间: 2012-10-23 12:12:22 作者: rapoo

新手求助, 这个程序死活通过不了

C/C++ code
/*  This is a little test file. You don't needt to use it unless you wish to  test the functions in WriteNumber.*/using namespace std;#include "WriteNumber.h"int main(char *args[]){   WriteNumber wn("file.dat");  // call the constructor.    wn.writeString(string("a number "));    wn.writeInt(33);    wn.writeInt(-4);    wn.writeDouble(44.5);    wn.close();    return 0; // normal exit}


每次编译都显示, 10 C:\Users\admin\Desktop\lab2\1\main.cpp new types may not be defined in a return type
10 C:\Users\admin\Desktop\lab2\1\main.cpp extraneous `int' ignored
10 C:\Users\admin\Desktop\lab2\1\main.cpp `main' must return `int'
C:\Users\admin\Desktop\lab2\1\Makefile.win [Build Error] [main.o] Error 1


[解决办法]
现在可以这样创建对象了啊?
WriteNumber wn("file.dat"); // call the constructor

不是很清楚,c++不是应该用new嘛?
WriteNumber wn = new WriteNumber("file.dat"); // call the constructor.
[解决办法]
WriteNumber.h贴一下
[解决办法]
new types may not be defined in a return type ===> WriteNumber.h文件最后缺少了分号 (;)。
[解决办法]
我不知道C++main函数里面的参数什么时候变成一个了,最少是两个,wmain里面有三个,第二,在.cpp文件中我没看见你写构造函数,不知道是什么情况
[解决办法]
int main(char *args[]) ==> int main(int argc, char *argv[])
[解决办法]
探讨

C/C++ code

#include<iostream>
#include<string>
#include<fstream>

#ifndef _WRITENUMBERS_H_
#define _WRITENUMBERS_H_

using namespace std;

class WriteNumber
{
private:
ofstream ……

读书人网 >C++

热点推荐