标签: reference

对类::方法C++的未定义引用

编译后面的源代码时出现问题:

    QString code = this->viewManager()->activeView()->document()->text();
    Qualifier qua;
    qua.setQCode(code);
Run Code Online (Sandbox Code Playgroud)

它告诉我

error: undefined reference to `Qualifier::setQCode(QString)'
Run Code Online (Sandbox Code Playgroud)

qualifier.h和.cpp的代码如下

#ifndef __QUALIFIER_H__
#define __QUALIFIER_H__

#include <iostream>
#include <string>
#include <QString>
#include <queue>
#include "analyser.h"



using namespace std;



class Qualifier
{

private:

    string code;
    queue<method> tokenisedCode;
    //queue<analysis> analysedCode;

void tokeniseCode();

public :


void setCode(string code);

void setQCode(QString code);

void computeLocAnalysis();

void computeCCAnalysis();

void visualiseResults();


};

 #endif /* __QUALIFIER_H__ */
Run Code Online (Sandbox Code Playgroud)

而且CPP是

#include "qualifier.h"

using namespace std;


void Qualifier::tokeniseCode()
{

Parser par;
par.setCode(code);
par.parse();
this->tokenisedCode = par.getMethods();

} …
Run Code Online (Sandbox Code Playgroud)

c++ reference

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

在C++中返回局部变量的引用

可能重复:
C++返回对局部变量的引用
可以在其范围之外访问局部变量的内存吗?

在以下代码中

int& h() {

int o=100;
return o; 
}

int main() {
int t=h();     //line 1
cout<<t;     //line 2
return 0;
}
Run Code Online (Sandbox Code Playgroud)

为什么输出为100,即函数的局部变量的值以及为什么第1行没有错误,因为函数的返回类型是int&但我们将其返回值返回到int.

c++ reference

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

C#容器通过引用或值初始化?

我对C++很有经验,但对C#来说有点新鲜.

将对象添加到容器时,它们是通过引用还是按值传递的?

也就是说,如果我这样做:

myClass m = new myClass(0);       //Assume the class just holds an int
List<myClass> myList = new List<myClass>(1);
myList.Add(m);
myList[0] += 1;
Console.WriteLine(m);
Console.WriteLine(myList[0]);
Run Code Online (Sandbox Code Playgroud)

结果会是:

0
1
Run Code Online (Sandbox Code Playgroud)

还是会的?

1
1
Run Code Online (Sandbox Code Playgroud)

如果是前者,那怎么能让我做到后者呢?我的第一直觉是做类似的事情

myClass ref mref = m; 
Console.WriteLine(mref);
Run Code Online (Sandbox Code Playgroud)

但这似乎不是有效的语法.

c# containers reference

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

使用字符串作为对象的引用

我希望将一些选项作为对象传递给我的jQuery插件.我是这样做的:

$("#contact-form").formValidate({
    contactname: {
        "minLength": 5
    },
    contactemail : {
        "minLength": 4
    },
    contactsubject : {
        "minLength": 10
    },
    contactmessage : {
        "minLength": 25
    }
});
Run Code Online (Sandbox Code Playgroud)

在我的函数中,我想用字符串引用对象,该字符串是表单字段的输入id.

$.fn.formValidate = function(options) {
        //...
        var $this = $(this);
        var id = $this.attr("id");
        var length = options.id.minLength;
       //...
}
Run Code Online (Sandbox Code Playgroud)

此解决方案不起作用.

//编辑

(function($, window, document, undefined ) {
    $.fn.formValidate = function(options) {
        /*
         * Deafults values for form validation.
         */
        var defaults = {
            minLength: 5,
            type : "text",
            required : true
        };

        var …
Run Code Online (Sandbox Code Playgroud)

javascript forms jquery reference object

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

字符串参考谜语

我遇到过以下代码谜语:

string a = "S1";
string b = "S2";
a = a+b;
Run Code Online (Sandbox Code Playgroud)

在此之后会留在内存中的是什么:

  1. "S1S2","S2"
  2. "S1","S1S2"
  3. "S1","S2","S1S2"

你有什么意见?为什么,在我看来(c)

  • 字符串指向 "S1S2"
  • 字符串b指向 "S2"
  • 并且"S1"即使在更换pointer/reference字符串a 之后也在后台

c# string reference

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

为什么这段代码不像我想的那样工作?

这是一个片段:

Test & returnref(){
    Test *obj = new Test();
    cout << &obj << endl;
    return *obj;
}

int main(){
    Test &object = returnref();
    cout << &object;

    cin.get();
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

并且此代码生成以下内容:

0016FBC8
004D4B98
Run Code Online (Sandbox Code Playgroud)

为什么不呢

0016FBC8
0016FBC8
Run Code Online (Sandbox Code Playgroud)

我认为,如果我返回对动态创建的对象(在堆上)的引用,它应该是完全相同的对象,因此地址应该相等.

为什么我错了?

c++ reference visual-studio-2010

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

.net如何管理内存参考共享?

我有一个有一个属性的班级

public class Test 
{
  public string Name { get; set; }  
}

private void TestReference()
{
    Test tst1 = new Test();
    tst1.Name = "ASP.NET";
    Test tst2 = tst1;
    tst1.Name = "JAVA";
    string name = tst2.Name; // Shows "JAVA" because of reference sharing 

    tst1 = null;

    bool isNullObj = tst2 == null; // isNullObj is false 
}
Run Code Online (Sandbox Code Playgroud)

在上面的示例中,当我设置tst.Name = "JAVA"此更改时也tst2.Name因为引用共享而反映出来 ,这个我理解但是当我设置时tst = null; tst2仍然活着.我的问题是,如果是分享参考!为什么tst2还活着?

.net c# reference

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

返回指针的C++方法:分段错误

下面的代码给了我一个分段错误,我尝试了很多不同的东西,但无法理解为什么它不起作用.我对C++很陌生,所以如果这个问题可能有点容易,我很抱歉;)这是我的代码:

 class Line2D
 {
 public:
   Point2D punkt; 
   double dx, dy; 
   void set_values(Point2D p, double d1, double d2);
   Point2D* getIntersectionPoint(Line2D& line2);
 };

 void Line2D::set_values(Point2D p, double d1, double d2)
 {
   punkt = p;
   dx = d1;
   dy = d2;
 }

 Point2D* Line2D::getIntersectionPoint(Line2D& line2)
 {
   double a, b;
   Point2D* intersec; 
   double det = dx*line2.dy - dy*line2.dx;
   if(det == 0)
   {
     return NULL;
   }
   else
   {
     double c1 = line2.punkt.k1 - punkt.k1;
     double c2 = line2.punkt.k2 - punkt.k2;
     a = (line2.dy*c1 - line2.dx*c2)/det; …
Run Code Online (Sandbox Code Playgroud)

c++ pointers reference segmentation-fault dereference

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

你能发现这个DLL的任何问题吗?

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EyesLib
{
    class Class1
    {

    public void drawEyes(int lookAtX, int lookAtY, int width, int height, Graphics eyeArea)
    {
        int xleft = 0, yleft = 0, xright = 0, yright = 0, xpleft = 0, ypleft = 0, xpright = 0, ypright = 0, reye = 0, rpupil = 0;
        xleft = width / 3;
        yleft = height / 2;
        xright = 2 * width / 3;
        yright …
Run Code Online (Sandbox Code Playgroud)

c# dll reference

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

函数中的c ++ - "引用...的错误无法用值初始化"

在花了一些时间挖掘相关帖子/在线资源后,我仍然对我的问题感到困惑.我的示例代码(test.cc)是:


void testsub(const int* &xx );
int main ()
{
 int* xx;
 xx= new int [10];
 testsub(xx);
 }
 void testsub(const int* & xx){}
Run Code Online (Sandbox Code Playgroud)

编译错误消息(pgcpp)读取

"test.cc", line 7: error: a reference of type "const int *&" (not const-qualified)
cannot be initialized with a value of type "int *"
  testsub(xx);
          ^
1 error detected in the compilation of "test.cc"."

为什么?非常感谢您的帮助.祝福,婷

c++ const reference

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