我想按属性将指针向量排序为指针向量,但是我不愿意这样做。 这是我的代码:
班级:
class Carro
{
//...
double positionX;
//...
double getXPosition() const; (i've tryed with and without const)
};
然后我在另一个类中有一个指针向量:
vector<Carro*> carros;
然后我有另一个向量,该向量指向前一个向量,并且仅指向某些元素,并且我试图按位置positionX的第二个向量对女巫进行排序;
#pragma once
#include <algorithm>
using namespace std;
vector<Carro*> carros2;
bool Pista::sortCarrosByPosition(Carro* p1, Carro* p2)
{
return p1->getXPosition() > p2->getXPosition();
}
sort(carros2.begin(), carros2.end(), sortCarrosByPosition);
我有以下错误:
see declaration of 'std::sort'
C2780: void std::sort(const _RanIt,const _RanIt)': expects 2 arguments - 3 provided
C2682: 'sort': no matching overloaded function found
C3867: 'Pista::sortCarrosByPosition': non-standard syntax; use '&' to create a pointer to member
我知道我想念一些东西,但不能完全动动手指...
答案 0 :(得分:0)
好吧,我宣布我的排序功能为静态:
package com.luv2code.hibernate.demo;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import com.luv2code.hibernate.demo.entity.Instructor;
import com.luv2code.hibernate.demo.entity.InstructorDetails;
import com.luv2code.hibernate.demo.entity.Student;
public class CreateDemo {
public static void main(String args[]) {
//create session factory
Configuration con = new Configuration().configure("hibernate.cfg.xml").addAnnotatedClass(Instructor.class)
.addAnnotatedClass(InstructorDetails.class);
SessionFactory factory = con.buildSessionFactory();
Session session = factory.getCurrentSession();
try {
//create the objects
InstructorDetails tempInstructorDetail = new InstructorDetails("http://luv2code.com/youtube","Luv 2 code");
Instructor tempInstructor = new Instructor("Chad","lay","hasiay@.com");
tempInstructorDetail.setInstructor(tempInstructor);
tempInstructor.setInstructorDetailId(tempInstructorDetail);
session.beginTransaction();
session.save(tempInstructor);
session.getTransaction().commit();
System.out.println("done!");
}finally {
factory.close();
}
}
}
错误消失了,让我们看看它是否有效。