我在使用构造函数编译类链表时遇到此错误.我想做一个复制赋值运算符,但我得到这个错误'list :: list'命名构造函数,而不是类型.这条线是:
list::list& operator= (const list &l)
Run Code Online (Sandbox Code Playgroud)
list是我班上的名字
我正在尝试使用模板类,当我在LWS中的一个文件中编译它时,它可以工作:http: //liveworkspace.org/code/a9c412a7e683439dfa35a9363749369d
但是当我尝试编译它由3个文件组成时,
stack.h第4到21行
stack.cpp第24到48行
main.cpp第49行结束
当我尝试编译这3个文件时,我得到了
Undefined symbols for architecture x86_64:
"Stack2<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >::push(Node**, std::basic_string<char, std::char_traits<char>, std::allocator<char> >)", referenced from:
_main in ccCoizCT.o
"Stack2<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >::top(Node*&)", referenced from:
_main in ccCoizCT.o
"Stack2<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >::pop(Node*&)", referenced from:
_main in ccCoizCT.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)
是的我在stack.cpp和main.cpp文件中包含了stack.h
所以我想要一起编译几个文件.其中一个是包含stack.cpp的stack.h.
以下是我的头文件:
#include<iostream>
#ifndef STACK_H
#define STACK_H
template <class ItemType>
class StackType
{
public:
//code
private:
//code
};
#include "stack.cpp"
#endif
Run Code Online (Sandbox Code Playgroud)
以下是stack.cpp:
#include "stack.h"
#include <iostream>
using namespace std;
template<class ItemType>
StackType<ItemType>::StackType(){
top = -1;
MAX_ITEMS = 200;
}
//other codes
}
Run Code Online (Sandbox Code Playgroud)
当我说它我正在重新定义stack.cpp中的代码
以下是我的Makefile:
main.o: main.cpp stack.h
g++ $(CFLAGS) -c -o main.o main.cpp
stack.o: stack.cpp stack.h
g++ $(CFLAGS) -c -o stack.o stack.cpp
Run Code Online (Sandbox Code Playgroud)
我不知道问题是什么.
出于某种原因,当我试图做我的衍生物时,它只是对一个项目的导数而不是整个多项式.
struct term{
double coef;
unsigned deg;
struct term * next;
};
Run Code Online (Sandbox Code Playgroud)
我有一个结构,然后还有一个类Polynomial与深拷贝构造函数和=构造函数.在私人课堂上,我有一个term* ptr
这是我的衍生代码
void Polynomial::derivative (Polynomial *p){
term *x;
if ( ptr == NULL)
return ;
term *temp;
temp = ptr;
while (temp != NULL){
if ( ptr == NULL){
ptr = new term ;
x = ptr ;
}
else{
x -> next = new term ;
x = x -> next ;
}
x-> coef = temp -> coef * temp -> deg;
x-> deg …Run Code Online (Sandbox Code Playgroud) 我试图使用python导入龟但我得到一个错误:
Traceback (most recent call last):
File "turtle.py", line 1, in <module>
import turtle
File "/turtle.py", line 32, in <module>
turtle.pensize(2)
AttributeError: 'module' object has no attribute 'pensize'
Run Code Online (Sandbox Code Playgroud)
python是否附带龟或我必须单独下载?
我的python是2.7.2