我有一个名为'Card'的类,我试图将它的一些对象存储在std :: map Card.hpp中:
class Card
{
public:
enum ValueType { NOVALUE, ACE };
enum FaceType { NOFACE, CLUBS };
Card(const ValueType & _value, const FaceType & _face);
Card(const Card & _card);
private:
ValueType m_value;
FaceType m_face;
};
Run Code Online (Sandbox Code Playgroud)
以下是我存储和访问它的方法:Deck.hpp:
#include <map>
class Card;
class Deck
{
public:
Deck();
std::size_t length() const;
Card get_card(const int & _num);
private:
std::map<int, Card> m_deck;
};
Run Code Online (Sandbox Code Playgroud)
Deck.cpp:
#include "Card.hpp"
Deck::Deck()
{
m_deck.insert(std::pair<int, Card>(0, Card(Card::NOVALUE, Card::NOFACE)));
m_deck.insert(std::pair<int, Card>(1, Card(Card::ACE, Card::CLUBS)));
}
std::size_t Deck::length() const
{
return …Run Code Online (Sandbox Code Playgroud) 我写了一个简单的Trie实现.这是源代码:
#include <string>
#include <map>
typedef unsigned int uint;
class Trie {
public:
class Node {
public:
Node(const char & _value);
~Node();
char get_value() const;
void set_marker(const uint & _marker);
uint get_marker() const;
bool add_child(Node * _child);
Node * get_child(const char & _value) const;
void clear();
private:
char m_value;
uint m_marker;
std::map<char, Node *> m_children;
};
Trie();
~Trie();
bool insert(const std::string & _str);
bool find(const std::string & _str) const;
private:
Node * m_root;
};
// - implementation (in …Run Code Online (Sandbox Code Playgroud) 我有一个像这样的抽象类:
class A
{
public:
void func() = 0;
};
Run Code Online (Sandbox Code Playgroud)
我可以强制它的实现也有一个嵌套的迭代器类吗?
#include <iterator>
template<typename T>
class A
{
public:
class Iterator : public std::iterator<std::forward_iterator_tag, T>
{
};
virtual Iterator begin() const = 0;
virtual void func() = 0;
};
template<typename T>
class B : public A<T>
{
public:
B() {}
class Iterator : public std::iterator<std::forward_iterator_tag, T>
{
};
Iterator begin() const
{
return Iterator();
}
virtual void func()
{
}
};
int main()
{
B<int> b;
}
Run Code Online (Sandbox Code Playgroud)
我只是想知道这是否可行,如果是的话,我错过了什么?由于迭代器类将取决于如何实现类A,我不知道是否可以进行正式实现.
.hovereffect:hover > .hidden {
opacity: 1;
height: 1.5em;
padding: 0.5em 1em 0.5em 2em;
border: thin solid white;
transition-delay: 0s;
}
.hovereffect .hidden {
opacity: 0;
clear: both;
height: 0em;
padding: 0em;
border: none;
transition-property: opacity height padding border;
transition-duration: 400ms;
transition-delay: 1s;
}
nav {
float: right;
width: 15em;
margin: 0.1em 0em 0.1em 1em;
font-variant: small-caps;
}
nav a {
display: block;
background-color: #FBF0D4;
color: #725D29;
border: thin solid white;
padding: 0.5em 1em;
text-decoration: underline;
}
nav a:hover,
nav a:active …Run Code Online (Sandbox Code Playgroud)