小编Ada*_*yos的帖子

多个函数定义出错

我在几年前参加了一个入门课程后试图重新学习C++,而且我遇到了一些基本的问题.尝试使用友元功能时出现我当前的问题.这是我的2个文件中的代码.

第一:

// fun.cpp

#include <iostream>
using namespace std;

class classA {
    friend void funct();
public:
    classA(int a=1,int b=2):propa(a),propb(b){cout<<"constructor\n";}
private:
    int propa;
    int propb;
    void outfun(){
        cout<<"propa="<<propa<<endl<<"propb="<<propb<<endl;
    }
};
void funct(){                     // ERROR HERE
    cout<<"enter funct"<<endl;
    classA tmp(1,2);
    tmp.outfun();
    cout<<"exit funct"<<endl;
}
Run Code Online (Sandbox Code Playgroud)

第二:

// mainfile.cpp
#include <iostream>
#include "fun.cpp"
using namespace std;

int main(int nargin,char* varargin[]) {
    cout<<"call funct"<<endl;
    funct();
    cout<<"exit main"<<endl;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我得到的错误是"funct()'的多重定义".在将其声明为友元函数时,我使用了错误的语法吗?

c++ definition friend

44
推荐指数
2
解决办法
11万
查看次数

JScrollPane中的JTextArea将不会显示

我的GUI遇到了很大的问题.我的第一个问题是,当我按下导致我的JTextArea显示字符串的按钮时,他的文本区域会发生变化,从而推动我的GUI中的所有按钮和其他所有按钮.我尝试了很多解决方案,但没有任

我把我的文本区域放在一个可能有效或无效的滚动面板中.我不知道,因为滚动面板中没有显示任何文字.有人可以看看我的代码并告诉我我做错了什么吗?

谢谢

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class myClass extends JFrame implements ActionListener{
    public JButton picture = new JButton();
    public JTextArea description = new JTextArea(10,30);
    public JButton B1 = new JButton();
    public JTextArea C1 = new JTextArea();

    public myClass (String STP){

        super(STP);
        makeGUI();
    }

    public static void main(String[] args){
        myClass test = new myClass("story");
    }

    public void actionPerformed(ActionEvent event){
        Object source = event.getSource();
        if (source==B1){
            description.setText("hello world");
            C1.setText("hello world");
        }
    }

    public void makeGUI(){

        JScrollPane scroll = …
Run Code Online (Sandbox Code Playgroud)

java user-interface swing jscrollpane jtextarea

2
推荐指数
2
解决办法
908
查看次数

标签 统计

c++ ×1

definition ×1

friend ×1

java ×1

jscrollpane ×1

jtextarea ×1

swing ×1

user-interface ×1