如何将外部头文件中定义的struct
包含到另一个文件中?起初,我通过指针传递结构,所以我只需要一个前向声明。但是现在我想通过价值来传递并且无法进行编译。标题lagerverwaltung.h
确实包含结构,那么问题出在哪里?
档案lagerverwaltung.h
:
#ifndef LAGERVERWALTUNG_H
#define LAGERVERWALTUNG_H
struct etikettInfo{
QString userName;
QList<struct properties_content *> inhalte;
};
class Lagerverwaltung : public QMainWindow
{
Q_OBJECT
... and so on
};
#endif // LAGERVERWALTUNG_H
档案etikett1.h
:
#ifndef ETIKETT1_H
#define ETIKETT1_H
#include "lagerverwaltung.h" // for struct etikettInfo
class Lagerverwaltung;
//struct etikettInfo;
namespace Ui {
class Etikett1;
}
class Etikett1 : public QMainWindow
{
Q_OBJECT
public:
explicit Etikett1(Lagerverwaltung *mainwindow,
etikettInfo etikettData, // <- struct etikettInfo has not been declared
QWidget* parent = 0);
~Etikett1();
private:
Ui::Etikett1 *ui;
Lagerverwaltung *lgrvw;
etikettInfo etikettData; // <- struct etikettInfo does not name a type
};
#endif // ETIKETT1_H
如果重要:两个.h文件都有包括警卫。
好的错误消息(请参阅代码中的注释)非常具有描述性,但我不知道应该采取哪些不同的做法。
答案 0 :(得分:1)
此外,我还在lagerverwaltung.h中加入了etikett1.h
你的错误。您在etikett1.h
中加入了lagerverwaltung.h
,其中包括etikett1.h
,其中包含lagerverwaltung.h
,依此类推。换句话说,您有一个循环依赖。您的包含防护可以防止无限包含,但也会导致其中一个标头包含在另一个标头之前。在这种情况下,lagerverwaltung.h
首先包含在定义任何内容之前 - 特别是etikettInfo
- 它包括etikett1.h
...这取决于尚未定义的etikettInfo
。
如果lagerverwaltung.h
真正取决于etikett1.h
而且etikett1.h
中lagerverwaltung.h
所依赖的唯一内容是etikettInfo
而lagerverwaltung.h
中的任何内容都取决于etikettInfo
etikettInfo
然后最简单的解决方案是将etikett1.h
的定义拆分为另一个标头,并将其包含在lagerverwaltung.h
而不是require 'spec_helper'
describe file('/home/ravendra/backup.sh') do
its(:content) { should match /^ip=[$]1/ }
its(:content) { should match /^ssh_port=[$]2/ }
its(:content) { should match /^user=[$]3/ }
its(:content) { should match /^TIMESTAMP=`date \S%y-%m-%d\w%H-%M-%S`/ }
its(:content) { should match /^sh \/root\/backup_scripts\/openstack_backup.sh/ }
its(:content) { should match /^sh \/root\/backup_scripts\/dashboard_backup.sh/ }
its(:content) { should match /^tar -czvf musashi_backup-[$]TIMESTAMP.tar.gz \/musashi_backup/ }
its(:content) { should match /^backup_remote_server \(\) {/ }
its(:content) { should match /^rsync -rvaz --progress -e "ssh -p [$]ssh_port" musashi_backup-[$]TIMESTAMP.tar.gz [$]user@(.*?).(.*?).(.*?):(~)\// }
its(:content) { should match /^rsync -rvaz --progress -e "ssh -p [$]ssh_port" \/root\/backup_scripts\/restore.sh [$]user@(.*?).(.*?).(.*?):(~)\// }
its(:content) { should match /^}/ }
its(:content) { should match /^if \[ "[$]#" -eq 3 \]; then/ }
its(:content) { should match /^backup_remote_server/ }
its(:content) { should match /^fi/ }
its(:content) { should match /^rsync -rvaz --progress musashi_backup-[$]TIMESTAMP.tar.gz \/musashi_backup\// }
its(:content) { should match /^rsync -rvaz --progress \/root\/backup_scripts\/restore.sh \/musashi_backup\// }
end
describe file('/home/ravendra/backup_server.sh') do
its(:content) { should match /^ip=[$]1/ }
its(:content) { should match /^ssh_port=[$]2/ }
its(:content) { should match /^user=[$]3/ }
its(:content) { should match /^TIMESTAMP=`date \S%y-%m-%d\w%H-%M-%S`/ }
its(:content) { should match /^is_IP \(\) {/ }
its(:content) { should match /^local stat=1/ }
its(:content) { should match /^if \[\[ [$]ip =~ ^\[0-9\]{1,3}\\.\[0-9\]{1,3}\\.\[0-9\]{1,3}\\.\[0-9\]{1,3}[$] \]\]; then/ }
its(:content) { should match /^OIFS=[$]IFS/ }
its(:content) { should match /^IFS='.'/ }
its(:content) { should match /^ip=\([$]ip\)/ }
its(:content) { should match /^IFS=[$]OIFS/ }
its(:content) { should match /^\[\[ [$]{ip\[0\]} -le 255 && [$]{ip\[1\]} -le 255 \\/ }
its(:content) { should match /^&& [$]{ip\[2\]} -le 255 && [$]{ip\[3\]} -le 255 \]\]/ }
its(:content) { should match /^stat=[$]?/ }
its(:content) { should match /^echo [$]stat/ }
its(:content) { should match /^fi/ }
its(:content) { should match /^return [$]stat/ }
its(:content) { should match /^}/ }
its(:content) { should match /^ip_ping \(\) {/ }
its(:content) { should match /^if \[\[ [$]\(ping -q -c3 [$]ip\) == @\(*100% packet loss*\) \]\]; then/ }
its(:content) { should match /^echo "Unable to Ping the given Host"/ }
its(:content) { should match /^echo "Note : Please check the value of 'kernel parameter net.ipv4.icmp_echo_ignore_all' at the location '\/proc\/sys\/net\/ipv4\/'.\\/ }
its(:content) { should match /^If it's value is 1 then it will prevent other host from successfully pinging your server.In such case change it's \\/ }
its(:content) { should match /^value to 0 for successful pinging. Please try again."/ }
its(:content) { should match /^else/ }
its(:content) { should match /^ssh_validation/ }
its(:content) { should match /^fi/ }
its(:content) { should match /^}/ }
its(:content) { should match /^is_ssh_port \(\) {/ }
its(:content) { should match /^nc -z -w 3 [$]ip [$]ssh_port/ }
its(:content) { should match /^if \[ "[$]?" -ne 0 \]; then/ }
its(:content) { should match /^echo "Connection to" [$]ip "on port" [$]ssh_port "failed. Please try again."/ }
its(:content) { should match /^else/ }
its(:content) { should match /^echo "Connection to" [$]ip "on port" [$]ssh_port "succeeded"/ }
its(:content) { should match /^backup_server/ }
its(:content) { should match /^fi/ }
its(:content) { should match /^}/ }
its(:content) { should match /^backup_server \(\) {/ }
its(:content) { should match /^tar -czvf musashi_backup-[$]TIMESTAMP.tar.gz \/musashi_backup/ }
its(:content) { should match /^rsync -rvaz --progress -e "ssh -p [$]ssh.port" musashi_backup-[$]TIMESTAMP.tar.gz [$]user@(.*?).(.*?).(.*?):(~)\// }
its(:content) { should match /^rsync -rvaz --progress -e "ssh -p [$]ssh.port" \/root\/backup_scripts\/restore.sh [$]user@(.*?).(.*?).(.*?):(~)\// }
its(:content) { should match /^create_cron/ }
its(:content) { should match /^}/ }
its(:content) { should match /^ip_validation \(\) {/ }
its(:content) { should match /^return_val=[$]\(is_IP\)/ }
its(:content) { should match /^if \[ "[$]return_val" == 0 \]; then/ }
its(:content) { should match /^ip_ping/ }
its(:content) { should match /^elif \[ "[$]return_val" == 1 \]; then/ }
its(:content) { should match /^echo "IP address should be in range of 0 to 255"/ }
its(:content) { should match /^else/ }
its(:content) { should match /^echo "Please put a valid IP addres"/ }
its(:content) { should match /^fi/ }
its(:content) { should match /^}/ }
its(:content) { should match /^is_ssh \(\) {/ }
its(:content) { should match /^local stat=1/ }
its(:content) { should match /^if \[\[ [$]ssh_port =~ ^\(\[0-9\]{1,4}\|\[1-5\]\[0-9\]{4}\|6\[0-4\]\[0-9\]{3}\|65\[0-4\]\[0-9\]{2}\|655\[0-2\]\[0-9\]\|6553\[0-5\]\)[$] \]\]; then/ }
its(:content) { should match /^stat=[$]?/ }
its(:content) { should match /^echo [$]stat/ }
its(:content) { should match /^fi/ }
its(:content) { should match /^return [$]stat/ }
its(:content) { should match /^}/ }
its(:content) { should match /^ssh_validation \(\) {/ }
its(:content) { should match /^return_val=[$]\(is_ssh\)/ }
its(:content) { should match /^if \[ "[$]return_val" == 0 \]; then/ }
its(:content) { should match /^is_ssh_port/ }
its(:content) { should match /^else/ }
its(:content) { should match /^echo "Please put a valid SSH port number. It should be in range of 0 to 65535."/ }
its(:content) { should match /^fi/ }
its(:content) { should match /^}/ }
its(:content) { should match /^ create_cron \(\) {/ }
its(:content) { should match /^\( crontab -l \| grep -v \/root\/backup_scripts\/backup.sh \) \| crontab -/ }
its(:content) { should match /^crontab -l \| { cat; echo "0 1 * * * \/root\/backup_scripts\/backup.sh [$]ip [$]ssh_port [$]user"; } \| crontab -/ }
its(:content) { should match /^}/ }
its(:content) { should match /^if \[ "[$]#" -eq 3 \]; then/ }
its(:content) { should match /^ip_validation/ }
its(:content) { should match /^else/ }
its(:content) { should match /^echo "Please provide valid number of arguments."/ }
its(:content) { should match /^fi/ }
end
中。
答案 1 :(得分:0)
原来是
struct etikettInfo{
QString userName;
QList<struct properties_content *> inhalte;
};
需要正确的包含才能成为正确声明的结构。所以添加
#include <QString>
#include <QList>
以及properties_content
的声明。