对于我的CS赋值,我需要编写一个实现容器接口的通用Bag对象.Bag应该只能容纳实现Thing界面的项目.我的问题是,当我尝试编译时,我得到了这个......
Bag.java:23: error: cannot find symbol
if (thing.getMass() + weight >= maxWeight) {
symbol: method getMass()
location: variable thing of type Thing
where thing is a type-variable:
Thing extends Object declared in class Bag
Run Code Online (Sandbox Code Playgroud)
getMass()方法在Thing界面中有明确定义,但我无法让Bag对象找到它.这是我的班级文件......
public interface Thing {
public double getMass();
}
public class Bag<Thing> implements Container<Thing> {
private ArrayList<Thing> things = new ArrayList<Thing>();
private double maxWeight = 0.0;
private double weight = 0.0;
public void create(double maxCapacity) {
maxWeight = maxCapacity;
}
public void insert(Thing thing) throws OutOfSpaceException …Run Code Online (Sandbox Code Playgroud) 我试图在C中通过引用传递结构,以便我可以修改函数内的值.这是我到目前为止的代码,但它会产生一些警告和一个错误.
main.c中
#include <stdio.h>
#include "myfunctions.h"
#include "structures.h"
int main(int argc, char const *argv[] {
struct MyStruct data;
data.value = 6;
printf("Before change: %d\n", data.value);
changeData(data);
printf("After change: %d\n", data.value);
}
Run Code Online (Sandbox Code Playgroud)
myfunctions.c
#include "structures.h"
void changeData(MyStruct data) {
data.value = 7;
}
Run Code Online (Sandbox Code Playgroud)
myfunctions.h
#ifndef MyStruct
#define MyStruct
void changeData(MyStruct data);
#endif
Run Code Online (Sandbox Code Playgroud)
structures.h
typedef struct {
int value;
} MyStruct;
Run Code Online (Sandbox Code Playgroud)
产生的错误
In file included from main.c:2:0:
myfunctions.h:4:1: warning: parameter names (without types) in function declaration
void changeData(MyStruct data);
^
In file …Run Code Online (Sandbox Code Playgroud)