Question

A C++ code error:Conditional jump or move depends on uninitialised value(s) at 0x4013EC: sdds::Ship::set(char const*, sdds::Engine*,...

A C++ code error:Conditional jump or move depends on uninitialised value(s)
at 0x4013EC: sdds::Ship::set(char const*, sdds::Engine*, int)

Here'are my class and set() function:

class Ship
{
Engine* engine;
char* s_type;
int engineNo;
float distance;
public:
Ship();
Ship(const char* sh_type, Engine* e, int e_No);
~Ship();
bool empty() const;
float calculatePower() const;
Ship& operator+=(Engine e);
void display() const;
void setEmpty();
bool isValid() const;
void set(const char* sh_type, Engine* e, int e_No);
friend bool operator==(const Ship&, const Ship&);
};

void Ship::set(const char* sh_type, Engine* e, int e_No)
{
if (e != nullptr && sh_type != nullptr && e_No > 0)
{   
delete[] engine;
delete[] s_type;
engine = new Engine[e_No];
for (int i = 0; i < e_No; i++)
{
this->engine[i] = e[i];
}
int size = strlen(sh_type);
s_type = new char[size + 1];
strcpy(this->s_type, sh_type);
s_type[size] = '\0';
engineNo = e_No;
}
else
{
setEmpty();
}
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

class Ship
{
Engine* engine;
char* s_type;
int engineNo;
float distance;
public:
Ship();
Ship(const char* sh_type, Engine* e, int e_No);
~Ship();
bool empty() const;
float calculatePower() const;
Ship& operator+=(Engine e);
void display() const;
void setEmpty();
bool isValid() const;
void set(const char* sh_type, Engine* e, int e_No);
friend bool operator==(const Ship&, const Ship&);
};

void Ship::set(const char* sh_type, Engine* e, int e_No)
{
if (e != nullptr && sh_type != nullptr && e_No > 0)
{   
if(engine !=NULL)delete []engine;
if(s_type !=NULL)delete []s_type;
engine = new Engine[e_No];
for (int i = 0; i < e_No; i++)
{
this->engine[i] = e[i];
}
int size = strlen(sh_type);
s_type = new char[size + 1];
strcpy(this->s_type, sh_type);
s_type[size] = '\0';
engineNo = e_No;
}
else
{
setEmpty();
}
}

Add a comment
Know the answer?
Add Answer to:
A C++ code error:Conditional jump or move depends on uninitialised value(s) at 0x4013EC: sdds::Ship::set(char const*, sdds::Engine*,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I need help with the code below. It is a C program, NOT C++. It can...

    I need help with the code below. It is a C program, NOT C++. It can only include '.h' libraries. I believe the program is in C++, but it must be a C program. Please help. // // main.c // float_stack_class_c_9_29 // // /* Given the API for a (fixed size), floating point stack class, write the code to create a stack class (in C). */ #include #include #include #include header file to read and print the output on console...

  • C++ When running my tests for my char constructor the assertion is coming back false and...

    C++ When running my tests for my char constructor the assertion is coming back false and when printing the string garbage is printing that is different everytime but i dont know where it is wrong Requirements: You CANNOT use the C++ standard string or any other libraries for this assignment, except where specified. You must use your ADT string for the later parts of the assignment. using namespace std; is stricly forbiden. As are any global using statements. Name the...

  • This is c++ programming and here is my code. I am getting an exception thrown on...

    This is c++ programming and here is my code. I am getting an exception thrown on the destructor for permanentworker. Can you tell me why I am getting this exception? #include <iostream> #pragma warning(disable:4996) class PermanentWorker { private:    char *name;    int salary; public:    PermanentWorker(const char* nam, int money) : salary(money)    {        name = new char[strlen(nam) + 1];        strcpy(name, nam);    }    int getPay() const    {        return salary;   ...

  • Overload the output stream operator << and the assignment operator =. Any time cout << task;...

    Overload the output stream operator << and the assignment operator =. Any time cout << task; is used the code should output a task, any time task1 = task2 is copied there must be a deep copy if there are pointers. Use the operators in the following code as suggested above. DO NOT simply overload them! Do so on the following code: //Project 4 Main function #include "functions.h" #include <stdlib.h> #include <stdio.h> //main int main(){    TaskList column("tasks.txt");    char...

  • In this assignment, you will implement a sort method on singly-linked and doubly-linked lists. Implement the...

    In this assignment, you will implement a sort method on singly-linked and doubly-linked lists. Implement the following sort member function on a singly-linked list: void sort(bool(*comp)(const T &, const T &) = defaultCompare); Implement the following sort member function on a doubly-linked list: void sort(bool(*comp)(const T &, const T &) = defaultCompare); The sort(…) methods take as a parameter a comparator function, having a default assignment of defaultCompare, a static function defined as follows: template <typename T> static bool defaultCompare(const...

  • 1. void raw_push_front(const Object &x) { // insert x at the head of the list *without*...

    1. void raw_push_front(const Object &x) { // insert x at the head of the list *without* using the iterator classes // Place your code here. } 2. void raw_push_back(const Object &x) { // insert x at the tail of the list *without* using the iterator classes // Place your code here. } #ifndef LIST_H #define LIST_H #include <algorithm> using namespace std; template<typename Object> class List { private: // The basic doubly linked list node. // Nested inside of List, can...

  • // thanks for helping // C++ homework // The homework is to complete below in the...

    // thanks for helping // C++ homework // The homework is to complete below in the stack.h : // 1. the copy constructor // 2. the assignment operator // 3. the destructor // 4. Write a test program (mytest.cpp) to test copy and assignment // 5. Verify destructor by running the test program in Valgrind // This is the main.cpp #include <iostream> #include "stack.h" using namespace std; int main() { Stack<int> intStack; cout << "\nPush integers on stack and dump...

  • //codes in DynamicString.cpp #include "DynamicString.h" int DynamicString::myStringLen(const char* str){ //TODO::Implement me return -1; } DynamicString::DynamicString(){ //TODO::1::Implement...

    //codes in DynamicString.cpp #include "DynamicString.h" int DynamicString::myStringLen(const char* str){ //TODO::Implement me return -1; } DynamicString::DynamicString(){ //TODO::1::Implement me } DynamicString::DynamicString(const char* str){ //TODO::1::Implement me } int DynamicString::len() const{ //TODO::1::Implement me return -1; } const char* DynamicString::c_str() const{ //TODO::1::Implement me return nullptr; } char& DynamicString::char_at(int position){ //TODO::1::Implement me char* a = new char('a'); return *a; } char DynamicString::char_at(int position) const{ //TODO::1::Implement me return 'a'; } char& DynamicString::operator[](int position){ //TODO::1::Implement me char* a = new char('a'); return *a; } char DynamicString::operator[](int position) const{...

  • Redesign your Array class from lab6 as a class template to work with the application below....

    Redesign your Array class from lab6 as a class template to work with the application below. write your overloaded output stream operator as an inline friend method in the class declaration. Include the class template header file in your application as below. #include "Array.h" main() {   Array<char> c(3);   c.setValue(0,'c');   c.setValue(1,'s');   c.setValue(2,'c');   cout << c;   Array<int> i(3);   i.setValue(0,1);   i.setValue(1,2);   i.setValue(2,5);   cout << i;   Array<int> j(3);   j.setValue(0,10);   j.setValue(1,20);   j.setValue(2,50);   cout << j;   Array<int> ij;   ij = i + j;   cout << ij;...

  • struct Item { string name; int quantity; float cost; }; const int MAX_SIZE = 50; class...

    struct Item { string name; int quantity; float cost; }; const int MAX_SIZE = 50; class ManageInventory { public: ManageInventory() : count{0}, p_pInventoryItems {new Item*[size]} { } ManageInventory(int size) : size{size}, count{0}, p_pInventoryItems {new Item*[size]} { } ~ManageInventory(); void addItem(string name, int quantity, float cost); private: int size {MAX_SIZE}; int count; Item ** p_pInventoryItems; }; Write the definition for addItem. Use the new operator to dynamically create instances of type Item. Store pointers to inventory items in the inventoryItems array....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT