Visual C++ のこれらのエラーについて教えてください。私は C++ の初心者で、NetBeans からこのコード (設計パターン Factory) をインポートしました。NetBeans では、このコードは正しいです。しかし、Microsoft Visual Studio 2010 でこのコードをコンパイルする必要があり、これらのエラーが発生しています。
Creator.h
#pragma once
#include "stdafx.h"
class Creator
{
public:
Product* createObject(int month);
private:
};
エラー:
- エラー C2143: 構文エラー: ';' がありません ' ' の前- 製品createObject(int month)
- エラー C4430: 型指定子がありません - int と見なされます。注: C++ は、オンラインで default-int をサポートしていません - Product* createObject(int month);
Creator.cpp
#include "stdafx.h"
Product* Creator::createObject(int month) {
if (month >= 5 && month <= 9) {
ProductA p1;
return &p1;
} else {
ProductB p2;
return &p2;
}
}
エラー:
IntelliSense: 宣言は " Creator::createObject(int mesic)" と互換性がありません (9 行目で宣言されています - これは Product createObject(int month); です)
stdafx.h:
#pragma once
#include "targetver.h"
#include <stdio.h>
#include <tchar.h>
#include <iostream>
#include <string>
using namespace std;
#include "Creator.h"
#include "Product.h"
#include "ProductA.h"
#include "ProductB.h"
Product.h:
#pragma once
#include "stdafx.h"
class Product
{
public:
virtual string zemePuvodu() = 0;
Product(void);
~Product(void);
};
製品.cpp:
次のものだけがあります。
#include "stdafx.h"
Product::Product(void)
{
}
Product::~Product(void)
{
}
答えてくれてありがとう。