Speak now
Please Wait Image Converting Into Text...
Embark on a journey of knowledge! Take the quiz and earn valuable credits.
Challenge yourself and boost your learning! Start the quiz now to earn credits.
Unlock your potential! Begin the quiz, answer questions, and accumulate credits along the way.
Course Queries Syllabus Queries 2 years ago
Posted on 16 Aug 2022, this text provides information on Syllabus Queries related to Course Queries. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.
Turn Your Knowledge into Earnings.
So I am working on an assignment in c++ where we are told to use an alias for a function, or at least for a function pointer (to my understanding). This is not regarded as "syllabus"(what we need to learn, don't know if this is the right word), and therefore has not been lectured.
To give a clearer understanding of the task, I have a class "Vehicle" with a function draw() that updates the speed of the vehicle and draws it to the screen. We are then told to use function pointers to move the input-part of draw() to a separate function. This separate function should be a private member of the class, initialized in the constructor. We are then told to use this "alias" to make the code easier to read:
draw()
using drivingAlgorithm = std::pair<double,double> ( PhysicsState ps, const std::vector<std::pair<double,double>>& goals, int currentGoal);
This should be placed in a different .h file, where the struct PhysicsState is also defined. My question is, How do I use this "alias"? More specifically, where do I define the actual body of the function I am using an alias for? I cant seem to find an answer in our textbook, and neither by searching Google.
PhysicsState
I think you've probably got the wrong end of the stick. There's nothing complicated here. Maybe a short sample will help.
include #include <utility> class PhysicsState { }; using drivingAlgorithm = std::pair<double, double>(PhysicsState ps, const std::vector<std::pair<double, double>>& goals, int currentGoal); class Vehicle { public: Vehicle(drivingAlgorithm da) : _da(da) {} private: drivingAlgorithm _da; }; std::pair<double, double> my_algorithm(PhysicsState ps, const std::vector<std::pair<double, double>>& goals, int currentGoal) { return std::make_pair(0.0, 0.0); } int main() { Vehicle v(my_algorithm); }
using x = ... just establishes a type alias, not a function alias (such a thing doesn't exist). In this case the type is a function type. But in any case you use the type alias just as you would use any other type.
using x = ...
No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.
Course Queries 4 Answers
Course Queries 5 Answers
Course Queries 1 Answers
Course Queries 3 Answers
Ready to take your education and career to the next level? Register today and join our growing community of learners and professionals.