我有一个列表,我保存由特定类创建的对象.
我想知道,因为我无法解决这个问题,如何从列表中删除该类的实例?
这应该基于知道对象的一个属性而发生.
我试图在头文件的类定义中定义字符串类型的变量.可能吗?例:
/* Foo.h */
#include <string>
class Foobar{
int a;
string foo;
}
Run Code Online (Sandbox Code Playgroud)
因为在某种程度上我可以声明一个字符串变量,但在标题中它不能识别我的字符串类型.
我正在尝试做一个我必须使用的家庭作业,fork()但我不知道为什么在通过我的for循环运行它们之后我无法阻止我的叉子:
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
int main(int argc, char *argv[]){
int limit = argc/2;
if(argc%2 == 0){
perror("the number of arguments given must pe even!");
exit(1);
}
int i;
for(i=0; i<=limit; i++){
if(fork()==-1){
perror("childes couldn't be created\n");
exit(1);
}
if(fork()==0){
printf("fork: %d \n",i);
exit(1);
}
wait(0);
}
printf("exiting...\n");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出:
warzaru@ubuntu:~/OS/UprocH$ ./exe a b c d
fork: 0
fork: 0
fork: 1
fork: 1
fork: 1
fork: 2
fork: 2 …Run Code Online (Sandbox Code Playgroud) 我需要一些提示或一个例子,我怎么能在列表中定位a列表b,然后用列表替换它c.
a=[1,3,6,2,6,7,3,4,5,6,6,7,8]
Run Code Online (Sandbox Code Playgroud)
输入b列表(这是程序在列表中搜索的子列表a).
b=[6,7]
Run Code Online (Sandbox Code Playgroud)
当找到返回我的索引是已找到的子列表并每次更换它c=[0,0],所以结果将是
[1,3,6,2,0,0,3,4,5,6,0,0,8]
Run Code Online (Sandbox Code Playgroud) 我正在努力学习课程,有些东西让我们回来了,我明白了
"NameError: global name 'self' is not defined"
Run Code Online (Sandbox Code Playgroud)
每个类字段都会发生同样的情况.你能帮我找到我做错了什么,谢谢你
码:
class Assignment:
def __init__(self, name, discription, deadline, grade, studentID):
self.name = name
self.studentID = studentID
self.description = discription
self.deadline = deadline
self.grade = grade
def __str__(self):
return "studentID:" + self.studentID + "assignment name:" + self.name +" description:" + self.description + " deadline:" + self.deadline + " grade:" + self.grade
def validation(self):
errors= []
if self.studendID == "":
errors.append("No existing student ID.")
if self.description == "":
errors.append("No existing description.")
if self.deadline …Run Code Online (Sandbox Code Playgroud) 我们假设我们有:
Class Foo{
int x,y;
int setFoo();
}
int Foo::setFoo(){
return x,y;
}
Run Code Online (Sandbox Code Playgroud)
我想要实现的只是形成我的get函数来返回多个值.我怎样才能做到这一点?
我是c ++的新手,我正在使用eclipse.
但是......我不知道为什么我在主函数中得到这个错误:
错误::: main必须返回int
我的代码是:
void main()
{
char a;
while (a!='q')
{
string ln = "enter option: ";
cout<< ln;
switch(a)
{
case 1:
if (a=='1')
func1();
break;
case 2:
if (a=='2')
break;
break;
}
}
}
Run Code Online (Sandbox Code Playgroud) 我在以下函数中遇到了这个错误.有谁知道它意味着什么?
template <class T>
void printAll(Array <T> &A){
for(int i=0; i<31; i++){
A.M[i].printObj; ///// ERROR
std::cout<<std::endl;
}
}
Run Code Online (Sandbox Code Playgroud)
该函数应该打印我的所有对象..printObj因为我在类打印功能中测试了它.谢谢,有关我可能忘记的任何细节,请询问.
我通过非模板函数传递模板函数的参数时遇到了一些麻烦.
让我知道我有这个:
template <class T>
void A(Array <T> &A) {
cout << "here";
}
void menu(Array<myType>& fooList) { // my type specified class type, created by me.
cout << "enter option ";
cin >> a;
switch {
case 1: A(fooList); break;
}
}
Run Code Online (Sandbox Code Playgroud)
我希望这个例子足够清楚.这可能吗?我可以将参数从非模板函数传递给模板函数吗?
编辑: - 自我试图构建的原型以来的实际代码没有帮助.
domain.h
template <class T>
void printAll(Array <T> &DBst, Array <T> &DBas){
for(int i=0; i<DBst.lenght; i++){
DBst.M[i].printStudent();
std::cout<<" ___ ";
DBas.M[i].printAssgn();
std::cout<<std::endl;
}
}
Run Code Online (Sandbox Code Playgroud)
或者Controller.h
template <class T>
void _printAll(Array <T> &DB1, Array <T> …Run Code Online (Sandbox Code Playgroud) c++ ×5
python ×3
class ×2
list ×2
c ×1
fork ×1
header ×1
indexing ×1
object ×1
overloading ×1
parameters ×1
return ×1
return-value ×1
search ×1
string ×1