带头和cpp的默认构造函数C ++

时间:2016-02-19 19:47:05

标签: c++ constructor default

所以我有这个练习是创建一个默认的构造函数DayOfYear,它将在某一天设置为1月1日。所以这个构造函数将被以下主要调用:

#include <iostream>
#include <cstdlib>
class DayOfYear
{
public:
    int month;
    int day;
    void output();
    DayOfYear();

};

所以我有这个标题:

#include <iostream>
#include <cstdlib>
#include "DayOfYear.h"
using namespace std;

DayOfYear::DayOfYear() :month(1), day(1)
{

}

以及以下cpp:

In file included from main.cpp:2:0:
DayOfYear.h:9: error: ISO C++ forbids declaration of ‘output’ with no type [-fpermissive]
 DayOfYear:: output();
                    ^
DayOfYear.h:9: error: extra qualification ‘DayOfYear::’ on member ‘output’ [-fpermissive]
 DayOfYear:: output();
 ^
In file included from DayOfYear.cpp:3:
DayOfYear.h:9: error: ISO C++ forbids declaration of ‘output’ with no type [-fpermissive]
 DayOfYear:: output();
                    ^
DayOfYear.h:9: error: extra qualification ‘DayOfYear::’ on member ‘output’ [-fpermissive]
 DayOfYear:: output();

所以我犯了很多错误,我尝试过很多东西,但是我无法弄清楚问题是什么。这些错误是;

      var azure = require('azure-storage');
      var path = ure = require('path');
      var _dir = process.cwd();

      process.env.AZURE_STORAGE_ACCOUNT = "ezcollaborate";
      process.env.AZURE_STORAGE_ACCESS_KEY = "qYwtbk/eI8gd+gO5+IOzEKBAixXDXBTiUd5s6Ar7xYUdbscqDflsYh887Glw/BYv1FfWnHWv4Kr71NS1wqTtkA==";
      var azureBlobUrl = "https://ezcollaborate.blob.core.windows.net/gallery/";

      module.exports = function(){
        var blobService = azure.createBlobService();
        var _checkContainer  = function(options, cb){
            if(options.container == null || options.container == "" ){

               options.container = "gallery"; 
            }
            var containerName =options.container; 

            blobService.createContainerIfNotExists(containerName, {publicAccessLevel : 'blob'},function(err, result, response) {
                if (err) {
                    console.log("Couldn't create container %s", containerName);
                    console.error(err);
                } else {
                    if (result) {
                        console.log('Container %s created', containerName);
                    } else {
                        console.log('Container %s already exists', containerName);
                    }

                    // Your code goes here
                }
            });
    }

    return {
        checkContainer:_checkContainer,
        uploadStream : _uploadFileFromStream
    }

  };

2 个答案:

答案 0 :(得分:0)

关于我使用完全不同的编译器所获得的错误消息,我无法回答你的问题,但是,这应该可以修复你的问题,并且可以在任何标准编译器上运行。

尝试编写您的课程:

<强> DayOfYear.h

#ifndef DAY_OF_YEAR_H
#define DAY_OF_YEAR_H

class DayOfYear {
private:
    int m_day;
    int m_month;

public:
     DayOfYear(); // Default Constructor
     explicit DayOfYear( int month = 1, int day = 1 ); // Constructor With Default Arguments

     void setDay( int day );
     void setMonth( int month );

     int getDay()   const;
     int getMonth() const;

     void display() const;  

private:
     DayOfYear( const DayOfYear& c ); // Not Implemented
     DayOfYear& operator=( const DayOfYear& c ); // Not Implemented
}; // DayOfYear

#endif // DAY_OF_YEAR_H

<强> DayOfYear.cpp

#include <iostream>
#include <cstdlib>
#include "DayOfYear.h"

// DayOfYear() - Default Constructor
DayOfYear::DayOfYear() :
m_day( 1 ),
m_month( 1 ) {
} // DayOfYear

// DayOfYear() - Constructor with default parameters
// If no values are passed it will default to 1-1
DayOfYear::DayOfYear( int month, int day ) :
m_day( day ),
m_month( month ) {
} // DayOfYear

// setDay()
void DayOfYear::setDay( int day ) {
    m_day = day;
} // setDay()

// setMonth()
void DayOfYear::setMonth( int month ) {
    m_month = month;
} // month

// getDay()
int DayOfYear::getDay() const {
    return = m_day;
} // getDay

// getMonth()
int DayOfYear::getMonth() const {
    return = m_month;
}

// display()
void DayOfYear::display() const {
    std::cout << "Month: " << m_month << " - " 
              << "Day: " << m_day << std::endl;
} // display

现在您可以将显示功能写出您喜欢或需要执行的任何文本格式,但这是一个有效的示例,可以编译,构建和运行而不会出错。

<强>的main.cpp

#include "DayOfYear.h"

int main() {

    DayOfYear someDay;
    someDay.display();

    return 0;

} // main

答案 1 :(得分:-1)

您的主要源文件不包括声明DayOfYear的头文件,因此不知道DayOfYear / output /等。甚至是。