在我的Gemfile中,我指定了:
ruby '1.9.3', engine: 'jruby', engine_version: '1.7.9'
Run Code Online (Sandbox Code Playgroud)
但进入我的Rails项目目录会rvm引发此错误:
RVM used your Gemfile for selecting Ruby, it is all fine - Heroku does that too,
you can ignore these warnings with 'rvm rvmrc warning ignore /home/petey/rails/kotoba/Gemfile'.
To ignore the warning for all files run 'rvm rvmrc warning ignore allGemfiles'.
ruby-1.9.3,engine:jruby,engine_version:1.7.9 is not installed.
To install do: 'rvm install ruby-1.9.3,engine:jruby,engine_version:1.7.9'
Run Code Online (Sandbox Code Playgroud)
但是,我确实安装了jruby 1.7.9:
$ rvm list
rvm rubies
jruby-1.7.9 [ x86_64 ]
ruby-1.9.3-p392 [ x86_64 ]
=* ruby-2.0.0-p247 [ x86_64 ] …Run Code Online (Sandbox Code Playgroud) 所以,我已经为obj1 + obj2进行了类内运算符重载:
fraction operator+ (fraction op);
Run Code Online (Sandbox Code Playgroud)
类似地,cout << obj正在通过重载运算符重载ostream来工作:
ostream& operator<< (ostream& os, fraction& frac);
Run Code Online (Sandbox Code Playgroud)
但是,如果我试图将两者结合起来,那么一切都会破裂.
fraction.cpp:77:27: error: no match for ‘operator<<’ in
‘std::operator<< [with _Traits = std::char_traits<char>]((* & std::cout), ((const char*)"Sum: "))
<< f1.fraction::operator+(f2)’
Run Code Online (Sandbox Code Playgroud)
这是代码:
#include <iostream>
using namespace std;
class fraction
{
private:
int n, d;
public:
fraction ()
{
this->n = 1;
this->d = 0;
}
fraction (int n, int d)
{
this->n = n;
this->d = d;
}
int getNumerator ()
{
return n;
} …Run Code Online (Sandbox Code Playgroud)