반복자 패턴을 사용하여 반복 및 인쇄하려고하지만 erorr이 표시됩니다.반복자 패턴 - 오류 C2679 : 바이너리 '<<': 'std :: string'유형의 오른쪽 피연산자를 사용하는 연산자가 없습니다.
여기오류이다
여기error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)
1> could be 'std::basic_ostream<_Elem,_Traits> &std::operator <<<char,std::char_traits<char>> (std::basic_ostream<_Elem,_Traits> &,const char *)'
가 오류 STD에서 시작 :: COUT < < menuItem->를 getName();
#ifndef _ROBOT1_
#define _ROBOT1_
namespace guitars {
namespace Composite {
namespace InventoryParts {
using namespace std;
#include <iostream>
//#include <string>
class Robot1 {
Menu* _partsMenu;
private:
public: Robot1(Menu* parts) : _partsMenu(parts) { assert(parts);
}
public: void printMenu() {
Iterator<MenuItem>* partsIterator = _partsMenu->createIterator();
std::cout << "Parts List" << std::endl;
printMenu(partsIterator);
}
private: void printMenu(Iterator<MenuItem>* iterator) { assert(iterator);
while(iterator->hasNext()) {
MenuItem* menuItem = dynamic_cast< MenuItem* >(iterator->next());
std::cout << menuItem->getName();
std::cout << menuItem->getPrice() << " -- ";
std::cout << menuItem->getDescription() << std::endl;
}
}
};
}
}
}
나는 그것의 다른 곳
#ifndef _ELECTRIC_MENU_ITERATOR_
#define _ELECTRIC_MENU_ITERATOR_
#include "Iterator.h"
namespace guitars {
namespace Composite {
namespace InventoryParts {
class ElectricMenuIterator : public Iterator<MenuItem> {
private: mutable std::vector< MenuItem* > _items;
private: mutable MenuItem* _position;
public: explicit ElectricMenuIterator(std::vector< MenuItem* > items) :
_items(items) {
_position = *items.begin();
}
public: MenuItem* next() const {
return _position;
}
public: bool hasNext() const {
for(std::vector< MenuItem* >::iterator iterator = _items.begin(); iterator != _items.end(); iterator++) {
if(*iterator == _position) {
if(++iterator != _items.end()) {
_position = *iterator;
return true;
}
else
return false;
}
}
return false;
}
};
}
}
}
#endif
반복자
#ifndef _ITERATOR_
#define _ITERATOR_
namespace guitars {
namespace Composite {
namespace InventoryParts {
template <class T>
class Iterator
{
public:
virtual bool hasNext() const = 0;
virtual T* next() const = 0;
virtual ~Iterator() = 0 {
}
};
}
}
}
#endif
메뉴
#ifndef _MENU_
#define _MENU_
#include "MenuComponent.h"
#include "InventoryItem.h"
#include "Iterator.h"
#include <assert.h>
#include <vector>
#include "MenuItem.h"
namespace guitars {
namespace Composite {
namespace InventoryParts {
class Menu : public MenuComponent {
private:
public:
virtual Iterator<MenuItem>* createIterator() const = 0;
virtual ~Menu() = 0 {
}
};
}
}
}
와 전기 기타 메뉴 넣다 이상의 파일이 포함됩니다
#ifndef _ELECTRIC_MENU_
#define _ELECTRIC_MENU_
#include "Menu.h"
#include "MenuItem.h"
#include "ElectricMenuIterator.h"
namespace guitars {
namespace Composite {
namespace InventoryParts {
class ElectricMenu : public Menu {
private:
std::vector< MenuItem* > _menuItems;
public: ElectricMenu() {
addItem("Electric Guitar","comes with an assortment of goodies",542.99);
//addItem("Regular acoustic","standard style",false,245.99);
}
public: void addItem(std::string name, std::string description, double price) {
MenuItem* menuItem = new MenuItem(name, description, price);
_menuItems.push_back(menuItem);
}
public: std::vector< MenuItem* > getMenuItems() const {
return _menuItems;
}
public: Iterator<MenuItem>* createIterator() const {
return dynamic_cast<Iterator<MenuItem>* > (new ElectricMenuIterator(_menuItems));
}
};
}
}
}
#endif
515,는 형식
내가 얻을 무리를 charater하기> menuItem-을 변경 getName()와 menuItem->으로 getDescription을 시도
볼 것 .. 그게 내가 왜 코멘트했는지 –
@ 셀렉트 : 글쎄, 만약'std :: string'을 사용하고 싶다면''헤더를 포함시켜야한다. 그렇게 할 때 에러가 발생하면, 이러한 오류를 해결할 수 있습니다. –
오류 C2039와 같은 오류가 발생합니다. 'cout': '기타 : Composite :: InventoryParts :: std'또는 'endl'의 멤버가 아닙니다 : '기타 :: 컴포지트 :: 인벤토리 파트 :: std'의 멤버가 아닙니다. –