我正在寻找做这样事情的最好方法:
class variable{
protected:
variable()
int convert[][]
}
class weight: variable{
public:
weight(){
convert = {{1,2},{1,3},{2,5}}
}
Run Code Online (Sandbox Code Playgroud)
现在我知道我不能这样做,因为我必须提前声明数组大小.我有很多类都继承自基类变量,而变量有一个使用convert的函数,所以不要分别在每一个中声明转换.对于每个类,数组长度将保持不变,因此使用列表似乎是不必要的.你有什么建议.
非常感谢.
我有一个类必须能够保持一种浮动,双重,长的异常.我想以这样的方式重载它,它可以添加两个持有不同类型的实例.
template <typename T>
class F{
public:
F(const T & t){a=t;}
T a;
F & operator+= (const F & rhs);
}
template<typename T>
F<T> F::operator+= (const F & rhs){
a+=rhs.a;
return *this
Run Code Online (Sandbox Code Playgroud)
这只是伪代码我已经保留了无关的位,我实际上试图使用这种解决方案.
现在尝试使用时:
F<int> first(5);
F<int> second(4);
first+=second; // Works
F<int> third(5);
F<float> fourth(6.2);
fourth+=third; // wont work
Run Code Online (Sandbox Code Playgroud)
我可以看出为什么这不起作用,因为它假设rhs参数与lhs的类型相同.我还可以看到在执行int + = long操作时存在潜在的问题,好像long很大,类型需要更改.我似乎无法找到解决问题的好方法.我很感激您的意见.谢谢
嗨,我正在尝试使用gnuplot-iostream,此时我只是想让代码在这里工作.当我尝试组合时,我在链接器中遇到错误:
In function `stream<int, boost::iostreams::file_descriptor_flags>':
/usr/include/boost/iostreams/stream.hpp:130: undefined reference to `boost::iostreams::file_descriptor_sink::file_descriptor_sink(int, boost::iostreams::file_descriptor_flags)'
In function `boost::iostreams::file_descriptor_sink boost::iostreams::detail::wrap<boost::iostreams::file_descriptor_sink>(boost::iostreams::file_descriptor_sink const&, boost::disable_if<boost::iostreams::is_std_io<boost::iostreams::file_descriptor_sink>, void>::type*)':
/usr/include/boost/iostreams/detail/wrap_unwrap.hpp:53: undefined reference to `boost::iostreams::file_descriptor_sink::file_descriptor_sink(boost::iostreams::file_descriptor_sink const&)'
In function `concept_adapter':
/usr/include/boost/iostreams/detail/adapter/concept_adapter.hpp:67: undefined reference to `boost::iostreams::file_descriptor_sink::file_descriptor_sink(boost::iostreams::file_descriptor_sink const&)'
/usr/include/boost/iostreams/detail/adapter/concept_adapter.hpp:38: undefined reference to `boost::iostreams::file_descriptor_sink::file_descriptor_sink(boost::iostreams::file_descriptor_sink const&)'
In function `long boost::iostreams::detail::write_device_impl<boost::iostreams::output>::write<boost::iostreams::file_descriptor_sink>(boost::iostreams::file_descriptor_sink&, boost::iostreams::char_type_of<boost::iostreams::file_descriptor_sink>::type const*, long)':
/usr/include/boost/iostreams/write.hpp:121: undefined reference to `boost::iostreams::file_descriptor::write(char const*, long)'
In function `void boost::iostreams::detail::close_impl<boost::iostreams::closable_tag>::close<boost::iostreams::file_descriptor_sink>(boost::iostreams::file_descriptor_sink&, std::_Ios_Openmode)':
/usr/include/boost/iostreams/close.hpp:224: undefined reference to `boost::iostreams::file_descriptor::close()'
In function `std::fpos<__mbstate_t> boost::iostreams::detail::seek_device_impl<boost::iostreams::any_tag>::seek<boost::iostreams::file_descriptor_sink>(boost::iostreams::file_descriptor_sink&, long, std::_Ios_Seekdir, std::_Ios_Openmode)':
/usr/include/boost/iostreams/seek.hpp:137: undefined reference to `boost::iostreams::file_descriptor::seek(long, std::_Ios_Seekdir)'
collect2: ld …Run Code Online (Sandbox Code Playgroud) 嗨,我正在尝试将第9列结果与第2列中以4.4开头的第一个点相对应.这是我到目前为止所拥有的.
echo $(awk "$2 ~ /4.4*/ {print $9}" 'myfile') >>"myoutputfile"
Run Code Online (Sandbox Code Playgroud)
不幸的是,这在语法上是不正确的,但我看不出如何解决它.任何帮助将非常感激.谢谢.