标签: include

通过包含访问函数与声明静态

我有一个头文件,我想包含在另一个cpp文件中.我想知道如果我写这样的头文件有什么区别,

#include <iostream>
#include <string>
using namespace std;

string ret()
{
return "called";
}
Run Code Online (Sandbox Code Playgroud)

===================================

#include <iostream>
#include <string>
using namespace std;

static string ret()
{
return "called";
}
Run Code Online (Sandbox Code Playgroud)

ret()无论如何我都可以访问这个功能!那么,静态的用途是什么?

c++ oop static include

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

如何通过C++预处理器#include包含部分文件

我想引用一些不是由我维护的稳定库代码.实际上它是一些MFC代码片段.

但是,每当我想要包含代码片段时,我都需要#include整个文件,因此我必须包含其他内容,然后是整个MFC ...结果是不可接受的.

目前,我将代码片段复制/粘贴到我的项目中,但我感到很可耻.我可以通过C++预处理器引用文件的一部分吗?

即使代码与特定的MFC版本硬连接,也比在我的项目中复制它们更好.有了这样的硬链接,我就会知道它来自MFC并节省我的时间来检查它们.

有一些超级#include用法吗?


我们能写点什么吗?

#include  "foo.h" line [12, 55)
Run Code Online (Sandbox Code Playgroud)

这意味着包括foo.h的第22行到第54行

c++ include c-preprocessor

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

php包含根目录以外的目录中的文件

我有一个全局模板页面,/layout_header.php以及存储的其他一些文件/aFolder/index.php.

/layout_header.php,我有:

<?php
    // Reference to scripts and other files
    echo "<img src='img/lollipop.png'/>";
    echo "<script src='js/move.js'/>";
    echo "<a href='aFolder/movement.php'>Click here!</a>";
?>
Run Code Online (Sandbox Code Playgroud)

/aFolder/index.php,我有:

<?php
    include "../layout_header.php";
?>
Run Code Online (Sandbox Code Playgroud)

现在,/aFolder/index.php调用该/layout_header.php文件没有问题.不幸的是,因为目录现在/aFolder,我面临以下问题:

  • 无法查看图像,因为图像现在链接为/aFolder/img/lollipop.png(不存在)
  • 由于上面列出的原因,无法执行脚本.
  • 由于上面列出的原因,网址无效.

我的许多脚本和css文件都使用相对路径.换句话说,如果index.php放在根文件夹中,一切正常.

我该如何解决子目录中的文件问题?

php include

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

"找不到资源"使用<include layout ="">时

在我的项目中,我创建了一个全局标题布局,global_header.xml并使用它在我的所有布局XML文件中使用它<include layout="@layout/global_header.xml">.

我之前使用过这种方法,目前我在这个项目中使用它.我的问题是我有一个包含以下内容的布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#FFFFFFFF" >

    <include layout="@layout/global_header" />

    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_below="@id/global_header">

        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >
        </RelativeLayout>
    </ScrollView>

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

内容global_header.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/global_header"
    android:layout_width="fill_parent"
    android:layout_height="60sp"
    android:layout_alignParentTop="true"
    android:background="#FFDDDDDD" >

    <ImageView
        android:id="@+id/global_header_logo"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="5sp"
        android:layout_marginTop="5sp"
        android:adjustViewBounds="true"
        android:src="@drawable/header" />

    <View
        android:layout_width="fill_parent"
        android:layout_height="1sp"
        android:layout_alignParentBottom="true"
        android:background="#FF000000" />

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

我说错了android:layout_below="@global/header":

错误:错误:找不到与给定名称匹配的资源(在'layout_below'中,值为'@ global/header').

我在项目中的其他布局中使用了include,它没有问题,但无论出于何种原因,此布局文件都不会像所有其他布局那样从标题中加载ID.

该项目不会构建此错误,即使我确信一旦在设备上运行它会发现它不是问题,还有其他人有这个问题吗?有解决方案/解决方法吗?

非常感谢任何和所有的帮助.

xml layout android include

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

使用jQuery包含一个JS文件

我实际上有一个使用jQuery包含JS文件的问题.我找到了很多来源,但没有人和我合作.我很确定js文件的路径是正确的.这是我的两次尝试:

第一个(我更喜欢)正在使用<link>(包括CSS文件),但它不使用<script>标签.

 $('head').append('<script type="text/javascript" src="'+addon+'"></script>');
Run Code Online (Sandbox Code Playgroud)


第二个是使用get HTTP请求.这是我的尝试:

 $.getScript(addon, function(){});
Run Code Online (Sandbox Code Playgroud)


所以,问题是:第一个代码出了什么问题?因为我之前用<link>标签试过它,它的工作非常好.

javascript jquery include

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

无法获得$ _POST值(php,html)

我无法从我的php文件中获取从html表单发送的$ _POST ['name']值.我见过很多类似的问题,但没有任何帮助.我有很多包含,所以我认为这是一个范围问题,但我无法弄明白.

的index.php

print_r($_POST); //Returns nothing, tried other ways too

//lot's of variables being defined

include 'sql_data_handlers.php';
//instantiating some things
Run Code Online (Sandbox Code Playgroud)

sql_data_handlers.php

//some functions retrieving data from sql db and finally:
include($DOCUMENT_ROOT . "page.html");
Run Code Online (Sandbox Code Playgroud)

page.html中

//html stuff
<?php
//Some conditions
include($DOCUMENT_ROOT . "comment_form.html");
?>
Run Code Online (Sandbox Code Playgroud)

comment_form.html

<form action="index.php" name="comment_form" id="comment_form" method="post">
    <input type="text" name="name" value="Anonymous" required><br>
    //lot's of inputs
    <input type="submit">
</form>
Run Code Online (Sandbox Code Playgroud)

我以前有,action="send_comment.php"但我意识到它可以变成一个函数,所以我ctrl + c并适应send_comments.php一个函数sql_data_handlers.php.问题是,现在我无法获取要在函数中使用的$_POST值(包括在内).index.phpsql_data_handlers.phpindex.php

我会使用,action="my_php_function_from_data_handlers.php($args)"如果有可能,但我想它不是.顺便说一下,我已经试过了action="".这可能看起来很乱,但这样我只需要一个.html用于站点布局,页面在sql上,而.php文件可以完成所有工作. …

php forms post scope include

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

C++包含文件混乱

我试图在我的c ++程序中包含文件,但我一直遇到错误:

ShapeVisitor.h:9:28: error: ‘Circle’ has not been declared

我认为问题在于类的结构方式,它导致循环依赖.我该如何解决这个问题?

类标题如下......

 //Circle.h
 #ifndef CIRCLE_H
 #define CIRCLE_H
 // headers, ...
 #include "Shape.h"
class Circle: public Shape { 
//class declaration 
}
#endif

//Shape.h
#ifndef SHAPE_H
#define SHAPE_H
// headers, ...
#include <iostream>

class Shape {  
//a certain method in the class declaration looks like this
virtual void accept(ShapeVisitor& v) = 0; 
//rest of class
}
#endif

//ShapeVisitor.h
#ifndef SHAPEVISITOR_H
#define SHAPEVISITOR_H
#include "Circle.h"
class ShapeVisitor {
//a method in the class looks …
Run Code Online (Sandbox Code Playgroud)

c++ header include forward-declaration

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

JSP - 将变量传递给servlet

如何将值= x从JSP传递给servlet?我搜索了许多相关的问题,但无法得到我的答案.这里x是一个变量.

<html>
<body>
<%@ page import="java.lang.*"%>
<%!int x,y; %>
<% String a,b;
a=request.getParameter("jobs");
b=request.getParameter("process");
x=0;
y=0;
try
{
 x=Integer.parseInt(a);
   y=Integer.parseInt(b);
}
catch(Exception e)
{ }
  out.println("You selected - <br>");
  out.println("Jobs - "+x+"<br>");
  out.println("Process - "+y);
   String path="table?input=x";
   %>

  <jsp:include page="table" > 
   <jsp:param name="input"  value=x/>
  </jsp:include>

</body>
</html>
Run Code Online (Sandbox Code Playgroud)

java variables jsp include

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

在msvc中可以像在emacs中一样打开include文件(visual c ++)

MSVC visual c ++允许您右键单击#include指令头文件(.h)并选择"打开文档".这使得浏览源代码变得轻而易举,因为它将整个源代码树基本上变成了一个超链接的网站.这些便利是否适用于emacs?是否有其他设备允许浏览源代码,您编写的任何代码,任何项目创建,所以自动?Xcode有吗?日食吗?有什么事吗?

ide emacs include visual-c++

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

在groovy脚本中包含类

如何在Groovy脚本中包含几个类?

(这个问题与REST无关,但我使用REST将问题放在正确的上下文中)

背景:我在groovy中开发CLI以从我们正在运行的服务获取状态信息.状态信息作为REST接口公开.

根据我在CLI上提供的参数,在REST接口上调用不同的路径.我还将实际的REST通信放在类层次结构中,以便能够重用代码,这就是我遇到问题的地方.如何以简单的方式在我的groovy脚本中包含类层次结构?

Groovy CLI脚本 RestCli.groovy

import restcli.RestA
import restcli.RestB

if(args[0] == "A") {
    new RestA().restCall()
}
else if(args[0] == "B") {
    new RestB().restCall()
}
Run Code Online (Sandbox Code Playgroud)

层级超级 restcli/RestSuper.groovy

package restcli

abstract class RestSuper {

    protected def restCall(String path) {
        println 'Calling: ' +path
    } 

    abstract def restCall()

}
Run Code Online (Sandbox Code Playgroud)

两个类实现不同的调用. restcli/RestA.groovy

package restcli

class RestA extends RestSuper {

    def restCall() {
        restCall("/rest/AA")
    }       

}
Run Code Online (Sandbox Code Playgroud)

restcli/RestB.groovy

package restcli

class RestB extends RestSuper {

    def restCall() {
        restCall("/rest/BB")
    }

}
Run Code Online (Sandbox Code Playgroud)

我想得到的结果很简单:

> …
Run Code Online (Sandbox Code Playgroud)

groovy class include

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