是否可以采用以下结构?
app.component.js
@NgModule({
imports: [CoreModule]
boostrap: [AppComponent]
app.module.js
@NgModule({
imports: [NavModule]
class CoreModule
core.module.js
@NgModule({
declarations: [NavContextComponent]
exports: [NavContextComponent]
class NavModule
nav.module.js
@Component({
selector: 'nav-context'
class NavContextComponent
NAV-context.component.js
'nav-context' is not a known element
到目前为止,我得到enter code here
// question #1.
// ADT for stack.
template <class type>
class abs_stack {
public:
virtual void initialize_stack() = 0; // starts the stack.
virtual bool isEmpty() = 0; // checks whether stack is empty or not.
virtual bool isFull() = 0; // checks whether stack is full or not.
virtual void push(type n) = 0; //
virtual void pop() = 0;
virtual type top() = 0;
};
// declaring array based stack.
template <typename t>
//template <typename E>
// class AStack: public Stack<E>
class aStack : public abs_stack<t> {
private:
t *grid; // stack.
int max_stack_size;
int top_element; // points to the top of the stack.
void stack_copy(aStack<t> ©); // used in copy contructor.
public:
aStack(int size); // paratmeterized constructor.
~aStack(); // destructor.
aStack(const aStack <t> &); // copy constructor.
const aStack<t> & operator =
(const aStack<t> &originalStack); // overloaded assignment operator.
//------------------------------------->
bool isEmpty() const;
bool isFull() const;
void pop();
void push(const t &newElem);
t top() const;
void initialize_stack();
};
enter code here
#ifndef H_stack
#define H_Stack
#include <iostream>
#include <cassert>
#include "stack.h"
using namespace std;
// stack methods' implementation.
template <class x> const aStack<x>& aStack<x>::operator=
(const aStack<x>& otherStack)
{
if (this != &otherStack) //avoid self-copy
copyStack(otherStack);
return *this;
}// end of overloaded assignment operator.
template <typename x>
void aStack<x> :: pop() {
if (!isEmpty()) {
top_element--; // decreases the position # of the top element.
}
else {
cout << "Error! Stack is already. Cannot remove anything." << endl;
}
} // end of pop()
template <typename x>
void aStack<x> :: push(const x &newElem) {
if (!isFull()) {
grid[top_element] = newElem; // places new element on the top
top_element++;
}
else {
cout << "No space available." << endl;
}
} // end of push
template <typename x>
x aStack<x> :: top() const {
assert(top_element != 0); // checks whether stack exists or not.
return grid[top_element - 1];
}
template <typename x>
void aStack<x>::initialize_stack() {
top_element = 0;
}
template <typename x>
bool aStack<x> :: isEmpty() const {
return (max_stack_size == 0);
}
template <typename x>
bool aStack<x> :: isFull() const {
return (top_element == max_stack_size);
}
template <typename x>
aStack<x> :: aStack(int size) {
if ( size <= 0) {
cout << "Error! Stack size can" <<
" never be lesser than/equal to 0." << endl
<< "Generating stack of size 10" << endl;
max_stack_size = 10;
}
else {
max_stack_size = size;
}
top_element = 0;
grid = new x[max_stack_size];
} // end of parameterized contructor.
template <typename x>
aStack<x> :: ~aStack() {
delete []grid;
grid = NULL;
max_stack_size = 0;
} // end of destructor.
template <typename x>
aStack<x> :: aStack(const aStack<x> &firstStack) {
grid = NULL;
stack_copy(firstStack);
} // end of copy contructor.
template <typename x>
void aStack<x> :: stack_copy(aStack<x> ©) {
delete []grid;
grid = NULL;
max_stack_size = copy.max_stack.size;
top_element = copy.top.element;
grid = new x[max_stack_size];
// generating deep copy of the original stack.
for (int i =0; i < max_stack_size; i ++)
grid[i] = copy.grid[i];
} // end of stack copy.
#endif
#include <iostream>
#include "stack.h"
using namespace std;
//--------- source file-->
int main() {
aStack<int> list(5);
return 0;
}
答案 0 :(得分:8)
如果您希望将模块提供给导入器,我认为您还需要导出模块
@NgModule({
imports: [NavModule]
exports: [NavModule]