所以我试图定义一个堆栈类,然后使用向量来创建一个通用堆栈.出于某种原因,当我尝试创建一个新堆栈时,我收到一条错误,说没有声明,我理解这一点,因为它说没有什么是基本上做的,我从来没有真正成为一个新的对象.我的确遵循了如何制作通用堆栈的指南. http://www.tutorialspoint.com/cplusplus/cpp_templates.htm
这是我使用的Stack类:
#ifndef stackers
#define stackers
#include <vector>
#include "Wrapper.hh"
template <class T>
class Stack {
private:
vector<T*> elems;
public:
Stack();
void push(T* obj); // push element
T* pop();
T* peek(); // pop element
T* findMax();
T* findMin();
bool isEmpty();
};
template <class T>
bool Stack<T>:: isEmpty(){
return elems.size()==0;
}
template <class T>
void Stack<T>::push (T* obj)
{
// append copy of passed element
elems.push_back(obj);
}
template <class T>
T* Stack<T>::peek ()
{
// append copy of passed element …Run Code Online (Sandbox Code Playgroud) 有疑问请澄清我让我解释一下A班和B班2班
public class A implements Cloneable{
public static void main(String[] args) {
A a1 = new A();
try {
A a2 = (A) a1.clone();//works fine
} catch (CloneNotSupportedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
B b1 = new B();
B b2 = (B) b1.clone();//cannot get this method
}
}
class B implements Cloneable {
}
Run Code Online (Sandbox Code Playgroud)
当我编译此代码得到以下错误
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method clone() from the type Object is not visible
Run Code Online (Sandbox Code Playgroud)
我知道这两个类扩展了Java.lang.Object类请解释为什么 …
我发现了这个问题,每当我尝试运行它时,它会给我一个错误,它无法编译,因为变量r尚未初始化.这是个问题....
int n=1; int k=2; int r;
if(k<r) {
r=n;
}
Run Code Online (Sandbox Code Playgroud)
"在if语句之后每个变量的值是多少?"
这样做时,我收到此错误:
The return type is incompatible with MouseAdapter.mouseClicked(MouseEvent)
Run Code Online (Sandbox Code Playgroud)
类:
public class MyMouseAdapter extends MouseAdapter
{
public MyMouseAdapter()
{
// TODO Auto-generated constructor stub
}
@Override
public String mouseClicked(MouseEvent e)
{
// TODO Auto-generated method stub
}
}
Run Code Online (Sandbox Code Playgroud)
哪里错了?原来的方法是public void mouseClicked(MouseEvent e)
这是代码的一部分
int main()
{
int x=5,y=10;
if(x=!y)
{
cout<<"h";
}
else
{
cout<<"p";
}
getch();
}
Run Code Online (Sandbox Code Playgroud)
输出是p,请解释,代码如何工作和意义x=!y.
(不确定是否允许我提出这样的问题,但如果被问到会删除)使用 8 位和 2 的补码格式将 -25 转换为二进制表示以表示负数。到目前为止,我得到了 11001。
我尝试使用 google 方法,但我不确定如何使用 8 位方式进行操作。
这个问题不是使用代码,只是转换,但我所做的是将其转换为二进制 11001 然后我添加了 3 个零使其成为 8 位(假设这是正确的) 00011001 然后我做了 1 的补码 11100110 和 2 的补码通过加 1等于 11100111。
我不确定这是否正确。
我目前有一个邮件服务器正在运行。我可以通过 mywebsite.com/roundcube/ 登录我的网络邮件客户端
网络邮件允许我适当地发送和接收电子邮件。日志显示所有进出的邮件都很好。我已经从这里发送到我的 gmail 帐户并返回。
但是,我真正想做的是使用 javax 邮件从 java 发送一些邮件。所以我可以自动化电子邮件
我试过如下配置:
final String username = "myusername";
final String password = "mypassword";
Properties props = new Properties();
props.put("mail.smtp.host", "localhost");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "25");
props.put("mail.debug","true");
// Get the Session object.
Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
session.setDebug(true);
Run Code Online (Sandbox Code Playgroud)
当我去发送消息时
Transport.send(message);
Run Code Online (Sandbox Code Playgroud)
我得到以下输出:
DEBUG: JavaMail version 1.5.0-b01
DEBUG: setDebug: JavaMail version 1.5.0-b01
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG …Run Code Online (Sandbox Code Playgroud) 我正在编写Web服务器的准系统,但我无法弄清楚为什么我的文件不能通过我的套接字发送,我正在连接到它以及它只是不在send()我的文件中...我是什么?失踪?
// CODE(server.c)
#include<netinet/in.h>
#include<stdio.h>
#include<stdlib.h>
#include<sys/socket.h>
#include<sys/stat.h>
#include<sys/types.h>
#include<unistd.h>
int main(void) {
int create_socket, new_socket;
socklen_t addrlen;
int bufsize = 1024;
char *buffer = malloc(bufsize);
struct sockaddr_in address;
if ((create_socket = socket(AF_INET, SOCK_STREAM, 0)) > 0){
printf("The socket was created\n");
}
address.sin_family = AF_INET;
address.sin_addr.s_addr = INADDR_ANY;
address.sin_port = htons(80);
if (bind(create_socket, (struct sockaddr *) &address, sizeof(address)) == 0){
printf("Binding Socket\n");
}
long fsize;
FILE *fp = fopen("index.html", "r");
fseek(fp, 0, SEEK_END);
fsize = ftell(fp);
rewind(fp); …Run Code Online (Sandbox Code Playgroud) 我有一个游戏的服务器/客户端模型,但它一直卡在ObjectInputStream初始化中。
下面是客户端启动方法的代码:
public void start(){
try {
Socket s = new Socket("127.0.0.1", 24680);
Thread.sleep(1000);
ois = new ObjectInputStream(s.getInputStream()); // stuck here
oos = new ObjectOutputStream(s.getOutputStream());
startGame();
} catch (Exception e) {
e.printStackTrace();
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是服务器代码:
try {
InputStream fis = socket.getInputStream();
ObjectInputStream ois = new ObjectInputStream(fis);
while (true) {
ArrayList < Dot > lists = (ArrayList < Dot > ) ois.readObject();
for (Socket s: sockets) {
ObjectOutputStream oos = new ObjectOutputStream(s.getOutputStream());
oos.writeObject(lists);
}
}
} catch (Exception …Run Code Online (Sandbox Code Playgroud) 我正在读《 c ++的完整指南》这本书。我认为第252页有错字。因此,我有以下三个文件。
在文件account.h中,
// account.h
// Defining the class Account. class definition (methods prototypes) is usually put in the header file
// ---------------------------------------------------
#ifndef _ACCOUNT_ // if _ACCOUNT_ is not defined
#define _ACCOUNT_
#include <iostream>
#include <string>
using namespace std;
class Account
{
private:
string name;
unsigned long nr;
double balance;
public: //Public interface:
bool init( const string&, unsigned long, double);
void display();
};
#endif
// _ACCOUNT_
Run Code Online (Sandbox Code Playgroud)
在account.cpp文件中,
// account.cpp
// Defines methods init() and display().
// ---------------------------------------------------
#include …Run Code Online (Sandbox Code Playgroud)