【问题标题】:The infamous 'function' was not declared in this scope臭名昭著的“功能”未在此范围内声明
【发布时间】:2012-06-11 10:34:31
【问题描述】:

我知道这个问题已经被问过很多次了,但我无法理解这个问题。这是我的头文件:

#ifndef TASK_H
#define TASK_H

#include "storage_adaptors.hpp"
#include <boost/numeric/ublas/vector.hpp>

class Task {
private:
    boost::numeric::ublas::vector<double> taskPosistionConstraint;
    boost::numeric::ublas::vector<double> initialPosition;
    boost::numeric::ublas::vector<double> finalPosition;
    double pathLength;
    int taskType;

public:
    Task();
    Task(double* _initialPoint, double* _finalPoint, int type);
    double getLength();
    int getTaskType();

    ~Task();
};

#endif  /* TASK_H */

这是cpp文件:

#include "Task.h"


const int TASK_SIZE = 3;

Task::Task() {
}

Task::~Task() {
}

Task::Task(double* _initialPoint, double* _finalPoint, int type) {

    finalPosition = make_vector_from_pointer(TASK_SIZE,_finalPoint);
    initialPosition = make_vector_from_pointer(TASK_SIZE, _initialPoint);

}

错误发生在storage_adaptors.hpp 中定义的make_vector_from_pointer 函数中,该函数包含在Task.h 中,这是一个boost hpp file。 如果将标头添加到类头文件中,为什么我会出现超出范围的错误:

Task.cpp:21:错误:“make_vector_from_pointer”未在 这个范围

【问题讨论】:

  • boost::numeric::ublas::make_vector_from_pointerusing namespace boost::numeric::ublas in cpp
  • 你能告诉我们缺少的声明吗?
  • 另外,拥有一个“Task”类和一个“Task”方法并不是一个好主意
  • @maverik,但是,在那个头文件中,已经添加了命名空间。我应该自己再做一次吗?
  • @Filip,是类的构造函数。

标签: c++ oop header scope


【解决方案1】:

如果是boost函数,不应该是boost::make_vector_from_pointer'吗?或者它所在的任何命名空间(如果不是直接在 boost 命名空间中)。

【讨论】:

  • 但是,在那个头文件中,已经添加了命名空间。我应该自己再做一次吗?
  • @Pouya:你的意思是在头文件中有using namespace boost;声明?我不这么认为。如果我是对的,那么 JohnB 的建议将解决您的问题。
  • 它在标题中,但是,在构造函数的主体中添加命名空间解决了这个问题。谢谢。
  • 一个通用的样式规则 - using namespace ...; 不应该在头文件中使用,除非包含在一些范围限制块中。
猜你喜欢
  • 2015-03-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-11-18
  • 1970-01-01
  • 2012-01-09
  • 2011-04-14
相关资源
最近更新 更多