Hi,
I've just recently started to learn C++, and I'm encountering some errors I can't seem to figure out.
InventoryItem.h:
Code:
#pragma once
class InventoryItem
{
public:
InventoryItem(string name, int amount);
~InventoryItem(void);
string getName(void);
int getAmount(void);
private:
string name;
int amount;
};
InventoryItem.cpp:
Code:
#include "stdafx.h"
#include "InventoryItem.h"
InventoryItem::InventoryItem(string name, int amount) : name(name), amount(amount) {}
InventoryItem::~InventoryItem(void) {}
stdafx.h:
Code:
#pragma once
#include "targetver.h"
#include "InventoryItem.h"
#include <stdio.h>
#include <tchar.h>
#include <iostream>
#include <string>
using namespace std;
Errors:
Code:
1>d:\c++\consoleapplication\consoleapplication\inventoryitem.h(6): error C2061: syntax error : identifier 'string'
1>d:\c++\consoleapplication\consoleapplication\inventoryitem.h(8): error C2146: syntax error : missing ';' before identifier 'getName'
1>d:\c++\consoleapplication\consoleapplication\inventoryitem.h(8): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\c++\consoleapplication\consoleapplication\inventoryitem.h(8): warning C4183: 'getName': missing return type; assumed to be a member function returning 'int'
1>d:\c++\consoleapplication\consoleapplication\inventoryitem.h(11): error C2146: syntax error : missing ';' before identifier 'name'
1>d:\c++\consoleapplication\consoleapplication\inventoryitem.h(11): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int