这是另一个“当我收到'没有匹配的调用函数'错误时,我的代码所带来的麻烦”。问题在于,有关该问题的问题是特定的,实际上并不能真正应用于一般代码。我的问题也很具体。
我的代码:
string largestNumber(vector<int>& nums)
{
string finalAnswer = "";
vector<int> answer{nums[0]};
if (nums.size() == 1)
{
return toStringconverter(nums[0]);
}
else
{
for (int i = 1 ; i < nums.size() ; i++)
{
answer.insert(getNumber(answer, nums[i]), nums[i]);
}
}
for(int i = 0 ; i < answer.size() ; i++)
{
finalAnswer = finalAnswer + toStringconverter(answer[i]);
}
}
我在answer.insert(getNumber(answer, nums[i]), nums[i]);
行中看到错误。这是leetcode编码站点上问题的解决方案的一部分。
很抱歉让我们解释得更好。 getNumber返回一个int。 int getNumber(vector&theList,int number)
答案 0 :(得分:0)
您可能想做的是将indexChanged()
之前的import UIKit
import CoreMotion
import CoreLocation
class PVOrientationViewController: UIViewController, CLLocationManagerDelegate {
//MARK: - Constants and Variables
let motionManager = CMMotionManager()
let locationManager = CLLocationManager()
var segIndex = 0
//MARK: - Outlets, views, actions
@IBOutlet weak var panelOptimalAz: UILabel!
@IBOutlet weak var panelOptimalTilt: UILabel!
@IBOutlet weak var panelCurrentAz: UILabel!
@IBOutlet weak var panelCurrentTilt: UILabel!
@IBOutlet weak var segmentedControl: UISegmentedControl!
//MARK: - Action of the Segmented Button.
@IBAction func indexChanged(_ sender: Any) {
segIndex = segmentedControl.selectedSegmentIndex
switch segIndex {
case 0:
print("Current Tab")
panelOptimalAz.text = "Tracking the Sun"
case 1:
print("3 months Tab")
// do something related to 3 months
case 2:
print("6 months Tab")
// do something related to 6 months
case 3:
print("Year tab")
// do something related to Year
default:
panelOptimalAz.text = "No Optimal Azimuth given"
panelCurrentAz.text = "No Current Azimuth given"
panelCurrentTilt.text = "No Current Tilt given"
panelOptimalTilt.text = "No Optimal Tilt given"
}
}
//MARK: - viewDidLoad()
override func viewDidLoad() {
super.viewDidLoad()
locationManager.delegate = self
// Azimuth
if (CLLocationManager.headingAvailable()) {
locationManager.headingFilter = 1
locationManager.startUpdatingHeading()
}
// start the motion manager here, since we want it running all the time
if motionManager.isDeviceMotionAvailable {
motionManager.deviceMotionUpdateInterval = 0.1
motionManager.startDeviceMotionUpdates(to: OperationQueue()) {(motion, error) -> Void in
if let attitude = motion?.attitude {
DispatchQueue.main.async{
self.panelCurrentTilt.text = "\(String(format:"%.0f", attitude.pitch * 180 / Double.pi))º"
}
}
}
print("Device motion started")
}else {
print("Device motion unavailable")
}
// call segment changed to update on start (as if user tapped seg 0)
self.indexChanged(segmentedControl)
}
//MARK: - Motion methods
// no need for this
// func myDeviceMotion() -> String{
//
// var currentTilt:String = "0.0º"
//
// return currentTilt
//
// }
//MARK: - True heading and panel's heading
func locationManager(_ manager: CLLocationManager, didUpdateHeading heading: CLHeading) {
let trueHeading = heading.trueHeading
//If latitude >= 0, then panel's azimuth = 180º, else, it is 0º
var panelHeading = 0.0
// I don't have your GlobalData object, so
// just hard-coding 1.0 here...
// if GlobalData.latit >= 0.0{
if 1.0 >= 0.0 {
// only update Optimal Az label if "Current" seg is NOT selected
if self.segmentedControl.selectedSegmentIndex != 0 {
self.panelOptimalAz.text = "180º"
}
panelHeading = trueHeading - 180.0
if panelHeading < 0{
panelHeading += 360.0
}
self.panelCurrentAz.text = "\(String(format: "%.0f", panelHeading))º"
}else{
// only update Optimal Az label if "Current" seg is NOT selected
if self.segmentedControl.selectedSegmentIndex != 0 {
self.panelOptimalAz.text = "0º"
}
panelHeading = trueHeading + 180.0
if panelHeading > 359.0{
panelHeading -= 360.0
}
self.panelCurrentAz.text = "\(String(format: "%.0f", panelHeading))º"
}
}
}
插入vector::insert(iterator position, const value_type& val)
中。
因此,您必须告诉编译器val
的实际功能以及如何将其position
的返回值转换为answer
。它可能像getNumber
一样简单,但最好更改int
以直接返回iterator
。