class

How can I overload char*? [duplicate]

不羁的心 提交于 2019-12-25 18:42:12
问题 This question already has answers here : How to pass optional arguments to a method in C++? (7 answers) Closed 6 months ago . I was asked that in a method class receive a char* and copy that in the member of the class, and if I don´t receive any parameter assign "Sin nombre" to the parameter void VEHICULO::Set_Nombre(const char* c){ //No problem here } int main(){ VEHICULO a; a.Set_Nombre("FERRARI");//ITS OK a.Set_Nombre(); //the class doesnt know that method } know how to copy the passed

How can I overload char*? [duplicate]

偶尔善良 提交于 2019-12-25 18:42:11
问题 This question already has answers here : How to pass optional arguments to a method in C++? (7 answers) Closed 6 months ago . I was asked that in a method class receive a char* and copy that in the member of the class, and if I don´t receive any parameter assign "Sin nombre" to the parameter void VEHICULO::Set_Nombre(const char* c){ //No problem here } int main(){ VEHICULO a; a.Set_Nombre("FERRARI");//ITS OK a.Set_Nombre(); //the class doesnt know that method } know how to copy the passed

inheritance Classes [closed]

萝らか妹 提交于 2019-12-25 18:33:45
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 3 years ago . Part A I'm trying to use the function that I have inside my base class "SHAPE" with the derived class "RECTANGLE" to create a bigger rectangle in my class "BIGRECTANGLE". I want to do have my sides transformation inside the class and not in the main, What should I do? Thanks! #include <iostream> using namespace

How to call constructor and variables from another class?

好久不见. 提交于 2019-12-25 18:29:29
问题 I have a main class: class Sportist{ private: string ime; int godina_na_ragjanje; int godisna_zarabotuvacka_EUR; public: Sportist(string i, int g_n_r, int g_z_EUR){ ime = i; godina_na_ragjanje = g_n_r; godisna_zarabotuvacka_EUR = g_z_EUR; } }; And now I have a new class like this: class Fudbaler:public Sportist{ private: int broj_na_odigrani_natprevari; int danocna_stapka; public: Fudbaler(string ime, int godina, int zarabotuvacka, int b, int d){ :Sportist(ime, godina, zarabotuvacka) broj_na

variable changes if I change a different variable

让人想犯罪 __ 提交于 2019-12-25 18:24:43
问题 Whenever I create an instance of a class, create a variable that's assigned that first instance, and use an attribute of the class on the second variable my first variable changes. class number: def __init__(self, value): self.value = value def add(self): self.value = self.value + 1 a = number(10) b = a b.add() a.value why does a.value give me 11 when I didn't use a.add() ? 回答1: @juanpa.arrivillaga provided good comments to your question. I just want to add how to fix your code to do what you

Setting up class instances in a multi view app (Objective C)

早过忘川 提交于 2019-12-25 18:24:10
问题 I am a newbie in Objective C, Xcode and so on. Thanks to your help, reading this forum, i did some steps in the right direction, but only in a "Single View Application". Now I have in my storyboard two views: (FirstViewController.h / m) (SecondViewController.h /m) I also created an Objective C class whom is meant to receive data from those two views. At first time, in the FirstViewController i had an IBA ACTION. When a button was pressed: controllo *control; control = [[controllo alloc] init]

Java: difference between “CustomClass1” and “CustomClass1.class”?

吃可爱长大的小学妹 提交于 2019-12-25 18:21:31
问题 This question is in continuation with Java: Using Classes as a value in hashmap. What is the difference between following two approaches?: 1) String name = ( ( CustomClass1 )obj1 ).getName(); and 2) String name = ( ( mapQuery2ResponseType.get("string1") )obj1 ).getName(); where, mapQuery2ResponseType.get("string1") return value of type Class<?> First approach works perfectly but in second approach it's giving an error saying Syntax error on token "obj1", delete this token . How can I modify

Create multiple instances of a class

元气小坏坏 提交于 2019-12-25 18:17:05
问题 I'm working on a space invaders type of game in Pygame. So far I just have the basics of the game down: import pygame, sys, os, math, random, time from pygame.locals import * pygame.init() window = pygame.display.set_mode((1000,500)) screen = pygame.display.get_surface() spaceBackground = pygame.image.load("C:/Users/LN/Desktop/space-background.png") spaceShip = pygame.image.load("C:/Users/LN/Desktop/space-ship.png") bullet = pygame.image.load("C:/Users/LN/Desktop/bullet.png") enemyShip =

How to use return value from method in Java?

主宰稳场 提交于 2019-12-25 18:16:27
问题 I want to use the return value from a member function by storing it into a variable and then using it. For example: public int give_value(int x,int y) { int a=0,b=0,c; c=a+b; return c; } public int sum(int c){ System.out.println("sum="+c); } public static void main(String[] args){ obj1.give_value(5,6); obj2.sum(..??..); //what to write here so that i can use value of return c //in obj2.sum } 回答1: try int value = obj1.give_value(5,6); obj2.sum(value); or obj2.sum(obj1.give_value(5,6)); 回答2:

Scanner.nextLine() throws java.util.InputMismatchException

隐身守侯 提交于 2019-12-25 18:12:49
问题 I'm new to classes and stuff like that. All I'm trying to do for now is to make the inventory hold one item and then when it works I'll research on how to make multiple Item objects and how to keep the program going so the "edit" and "remove" methods work. So basically this a test for an inventory and items project. Inventory class: When I run the project and enter a String: (S1) it tells me this: Exception in thread "main" java.util.InputMismatchException at java.util.Scanner.throwFor