小编Ben*_*Ben的帖子

g ++无法找到我的头文件

我正在尝试编译文件q1.cpp,但我不断收到编译错误:

q1.cpp:2:28: fatal error: SavingsAccount.h: No such file or directory
compilation terminated.
Run Code Online (Sandbox Code Playgroud)

头文件和头文件的实现都与q1.cpp完全在同一目录中。

文件如下:

q1.cpp

#include <iostream>
#include <SavingsAccount.h>
using namespace std;

int main() {
    SavingsAccount s1(2000.00);
    SavingsAccount s2(3000.00);
}
Run Code Online (Sandbox Code Playgroud)

SavingsAccount.cpp

#include <iostream>
#include <SavingsAccount.h>
using namespace std;

//constrauctor
SavingsAccount::SavingsAccount(double initialBalance) {
     savingsBalance = initialBalance;
}
SavingsAccount::calculateMonthlyInterest() {
     return savingsBalance*annualInterestRate/12
}
SavingsAccount::modifyInterestRate(double new_rate) {
     annualInterestRate = new_rate;
}
Run Code Online (Sandbox Code Playgroud)

SavingsAccount.h

class SavingsAccount {
    public:
        double annualInterestRate;
        SavingsAccount(double);
        double calculateMonthlyInterest();
        double modifyInterestRate(double);
    private:
        double savingsBalance; …
Run Code Online (Sandbox Code Playgroud)

c++ compilation g++ header-files

3
推荐指数
1
解决办法
1615
查看次数

你如何在界面中获得非抽象方法?

如何在不抽象的接口中创建方法?我知道可以做到,我只是不知道如何做.

我举一个例子来说明我的困惑.在Java中,您可以实现java.awt.event.MouseListener,然后必须调用方法addMouseListener(Object)...将您的类作为参数传递,以便MouseListener知道要从中转换的对象.addMouseListener(Object)方法如何可能?

有人说我对匿名类使用非抽象方法的接口的方式感到困惑.如何在接口中实现匿名类,以便实现者可以调用其方法?我很新,在OOP仍然是'noob'.

java oop methods interface class

2
推荐指数
3
解决办法
1万
查看次数

我的WebSocket没有按预期工作; 服务器用Java实现,客户端用JavaScript实现

我似乎无法在Java服务器和JavaScript客户端之间建立"正确"连接.它似乎连接好了,客户端发送它的标题好吧,但这是它得到的.onopen或者onmessage根本不会触发这些功能.

这是Java服务器的代码:

import java.net.*;
import java.io.*;
public class Server {
    static DataOutputStream out;
    public static void main(String[] args) {
        try {
            ServerSocket serverSocket = new ServerSocket(8112);
            System.out.println("Server Started");
            while(true) {
            Socket socket = serverSocket.accept();
            System.out.println("A client connected");
            out = new DataOutputStream(socket.getOutputStream());

            //Send a simple-as-can-be handshake encoded with UTF-8
            String handshake = "HTTP/1.1 101 Web Socket Protocol Handshake\r" +
            "Upgrade: WebSocket\r" +
            "Connection: Upgrade\r" +
            "WebSocket-Origin: http://localhost\r" +
            "WebSocket-Location: ws://localhost:8112/\r" +
            "WebSocket-Protocol: sample\r\n\r\n";
            out.write(handshake.getBytes("UTF8"));
            System.out.println("Handshake sent.");

            //Send …
Run Code Online (Sandbox Code Playgroud)

javascript java html5 utf-8 websocket

1
推荐指数
1
解决办法
2966
查看次数

标签 统计

java ×2

c++ ×1

class ×1

compilation ×1

g++ ×1

header-files ×1

html5 ×1

interface ×1

javascript ×1

methods ×1

oop ×1

utf-8 ×1

websocket ×1