C# :: List Initialize In Object Initialization Method
Oct 31, 2014
public class Customer
{
public int Id { get; set; }
public string Name { get; set; }
public List<Order> Orders { get; set; }
public Customer() {
Orders = new List<Order>();
}
}
This object is called as
var cust = new Customer
{
Id = 1, Name = "Khatana", [b]Orders.Add(new Order())[/b]
}
I want to ask, Orders.Add(new Order()) is a wrong way, but why..!!... as List<Order> already has been initialized in Customer constructor, then why it is again required to be initialized in object initialization.
Is this a correct way
List<Order> orders = new List<Order> {aaa.....bb....cc};
var cust = new Customer
{
id = 1, Name = "Khatana", Orders = new List<Order> { orders }
}
Why we need to initialize a list in an object initialization, where as the list has been already initialized in object constructor.
View 2 Replies
ADVERTISEMENT
Mar 16, 2013
will copy constructor does object initialization using another already created object? I understand that it can be applied for object initialization and not for assignment.Is it correct?
View 10 Replies
View Related
Sep 14, 2013
I need to create a method (constructor) to initialize a bigint to an int value you provide [0, maxint].
Example: bigint(128).
Here is my class:
#ifndef BIGINT_H
#define BIGINT_H
const int MAXINT = 500;
class bigint{
public:
bigint();
[Code] ....
So if the user inputs (4123 for example). How would I make 4 in size[0], 1 in size [1], 2 in size [2], etc. I don't even know where to start. Im guessing I would start with a for loop. It has to be an integer. I cant use a string yet.
View 2 Replies
View Related
Jul 3, 2014
I have a method to take a Tile object and make an instances of it based on some data from the original object. Than it is suppose to manipulate the a specific instance and save the results. The first loop through it works but it changes all instance as well as the base.
public static int recurse(int count, Tile[,] b,Huristic h,int check) {
if (check==1) {
boardState.Add(B)/>;
return check;
} if (check == 0)
[Code] .....
View 6 Replies
View Related
Mar 6, 2013
I want to make a class, named generation, having a vector<chromosome> type data member.
chromosome is also class name.
chromosome has a 'route' as data member, which type is class TArrayI defined in ROOT package.
the size of route is to be fixed according to parameters of generation class object.
class chromosome{
public: chromosome(){;}
....
protected:
TArrayI route;
};
class generation{
public: generation(int PopSize=300, int numCity = 36){
.........
}
vector<chromosome> Population;
};
I want each element, chromosome of Population, to have a numCity size of route.
View 2 Replies
View Related
Jun 17, 2014
i'm currently working on a research project and i've been given some specifications
Is there a way i can access/use the array initialisation list i.e
{value,value,value}; .
For my own class? Like this
myclass foo={value,value,value};
View 3 Replies
View Related
Oct 17, 2012
I am studying the creation of classes in C + +. When executing the code below the method LEN class String2 not work.
code ----------------------------------------------------------------------------------------------
#include <iostream>
#include <string.h>
using namespace std;
[Code]......
View 4 Replies
View Related
Apr 29, 2014
I am new to c++ and trying to learn. for instance. i have a struct and method.I am trying to learn what i can do with the method if i define the return type as struct type.
struct S {
int age;
string name;
};
S method() {
//what i can do in here. with the Struct. I mean can i reach members of the struct. etc
}
View 2 Replies
View Related
Sep 18, 2014
I got base class called Statistic and inherited classes from it : lsp, cpu, memory. Those methods inheriting some of methods from Statistic and implement also theirself methods. I prepared some new class called ExecuteRequest which is taking Statistic object in the constructor. What i want to achieve is after i put e.g LSP to this class i would like to determinate what specific object it is in this case LSP right? Then having that i would like to put this object to RunRequest method. How can i achieve that? See my code below:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SOAP_testing {
public class ExecuteRequest
[Code] .....
View 14 Replies
View Related
Feb 21, 2013
I am trying to write a program which involves linked list. i have to create a method called add_aa( str ). I am reading from a text file. in the text file it just contains the values for str. what I am trying to do is create the method add_aa( str ) and add what corresponds to str from the file. here is what the output should look like. and what i have is very basic. here is what i have
inline void LList:: add_aa(const string _str) {
cout << " p = " << std::hex << p << std::dec << '
';
}
I'm thinking using a for statement, but how to incorporate it
Attached Images : sample.JPG (35.2 KB)
View 1 Replies
View Related
Apr 3, 2013
I am making a custom linked list (for fun!) and want to implement a sort method that sorts the stored data using the stored types > and < operators (will require the type to have these operators overloaded)
What is the best way to do this? I guess the first thing one might jump to would be to compare the current node with the the node to its "right" see if one is greater than the other. Then keep iterating through the list until you don't swap any more nodes. However I am thinking there is probably a more efficient way to do this. Here is my code so far:
#ifndef LIST_HPP
#define LIST_HPP
#include <string>
[Code].....
Surely there is a way to sort with only one iteration through the list?
View 2 Replies
View Related
Mar 17, 2015
I want to write how many times a method is called. The first class houses a method that I want to count from the second class how many times it is called. what I am able to achieve so far is that it only writes out how many times it is called but what I want is that it should be like a counter like this: if called ofr 5 times it should print:
1
2
3
4
5
and not just 5.
First class
public static int count = 0;
public void Login(String LoginUsername, String LoginPassword) {
count++;
}
Second class
int i = LoginReusables.count;
i++;
System.IO.File.WriteAllText(@"C:Usersken4wardDesktopTidyWriteLines.txt", i.ToString());
View 11 Replies
View Related
Jan 17, 2013
I've been trying for more than one month to access a method found in a library called libcocosnas_static.a. I'm using Cocos2d-X version 2.0.4. The library has been used many times by my company to make games using cocos2d-1.0.1-x-0.12.0 without any problem.
This is what I've done:
1- I added the include paths of the library to both eclipse and Android.mk
2- Included the .h file using #include "NASPlatformUtil.h"
3- Added the libcocosnas_static.a file to the proj.androidobjlocalarmeabi folder
4- Added "LOCAL_WHOLE_STATIC_LIBRARIES += cocosnas_static" to the Android.mk file
5- Called the function using: NASPlatformUtil:: openUrl("http://xxx.xxx.com/");
I can right click on the function, click Open Declaration and get it without any problem, but the compiler keeps on giving me that dreaded error...
View 3 Replies
View Related
Feb 10, 2014
I have a standard linked list in template format (with T being the typename) with the following relevant insertion operators:
bool PushFront (const T& t); // Insert t at front of list
bool PushBack (const T& t); // Insert t at back of list
I want to build a list of pointers to objects (we'll call them objects of class Box for simplicity) that is member data for a parent class (we'll call that class Warehouse). However, I want to have a constant Box....const Box INVISIBLE_BOX = Box(); that represents a nonexistent Box. However, I cannot use either
PushFront(&INVISIBLE_BOX)
or
PushBack(&INVISIBLE_BOX)
to add INVISIBLE_BOX to the list of boxes without getting an invalid conversion error invalid conversion from âconst warehouse::Box*â to âwarehouse:: Box*â [-fpermissive]
What can I do to make it take a constant Box? I am using g++ to compile these files.
View 1 Replies
View Related
Nov 6, 2014
I've been struggling with an object when trying to add it to a list with [Listname].push_back. You see, I have a list with some objects that will be rendered in the screen (Called objects) and a function to create a text box with some text. The function in question is the following:
void reprEv(int evNum, ALLEGRO_BITMAP *txtbxim) //Event to call, default text box image.
{
textBox *txtBox = new textBox("Line 1 ", "Line 2 ", "Line 3 ", "Line 4 ", "Line 5 ", textboximage);
objects.push_back(txtBox);
[Code]....
(txtNum is increased then space is pressed, and when certain screen (maxScreen) have been shown, then it will go to the playing state)
My problem begins when the text box is created, because it's supposed to add only 1 text box to objects list, but instead adds hundreds of text boxes to objects.
View 1 Replies
View Related
Nov 4, 2014
I've changed up my code to the retail checkout WFA I am trying to make. I have an item list filled with objects of the now globally accessible 'Item' class, but I'm having trouble.
Essentially, I want to send an object of the item class chosen from a dropdown menu to form2, where I will fill in certain blank attributes with data entered in form2's text boxes and comboboxes. The problem, it seems, is I need another itemlist in form2 that will hold the object being passed to form 2, so I can then pass all the information to textboxes on form3 (the receipt/review page). It's been more than a year since I coded with C#, and I've forgotten quite a bit. I was also not able to find any tutorials on building an item list without an associated combobox or droplist, which is what I need.
This is my item class (minus most of its properties so the page doesn't stretch).
class Item {
public string prodName;
public string fName;
public string lName;
public string ccNum;
public string ccProv;
public string shipAddr;
[code] ....
For anyone who didn't see my last question, I'm in a User Interface Design class, not a C# class. I know this probably isn't the best code out there, but for my purposes the program just needs to compile beginning to end and pass the data like it should.
View 1 Replies
View Related
Oct 7, 2012
Have tried to track down the delay? Which function takes that long? Have you printed some logs or measured the time of the functions? No I am not sure how to do that! I debugged it but i didn't see any difference! I definitely think its the logic in the receive code that's "inefficient" what do you think about that? Do you think there's a more efficient way of receiving messages and sending them? Because what I am doing is receiving one then calling send and sending that message out to all users then receiving another one then calling send and sending it out to all users and repeating that process till all the messages are sent, both methods are using a loop to send to all users. DO you think i should receive all messages then send them all out at once? or is that less efficient?
View 4 Replies
View Related
Apr 14, 2014
I'm having a problem trying to modify my patient's data. It seems to work, but once the block of code ends it does not save to the linked list.
Problem located in case M.
linked list template header: [URL] ...
patient header: [URL] ...
patient implementation: [URL] ...
#include <iostream>
#include "listTemplate.h"
#include "PatientRecord.h"
using namespace std;
char menu() {
char input
[Code]...
View 1 Replies
View Related
Apr 9, 2014
i have a program that is a Mediastore and i have 4 classes. Produkt: which is a class with a few variables that i use to add products to my List.
public class produkt
{
public string Name;
public string price;
[Code]....
then i have my Lager class which i use to add my products to my list and Listbox. This is done by having 3 textfields where i say what the Name,SerialNumber and Price of the object i created should have.
In this class i also have 2 more textfields and a button that make it possible to add a quantity of the selected listbox object of my product Class. if the item im trying to add a quantity to dosent exist i get a question if i wanna add that product and it adds that product to the list. if however the product allready exist its suposed to add the quantity with the selected amount from my textbox.
Then I have my Class Kassa which is a Form with 2 Listboxes. The first listbox share the same List as the one in my Lager class and the other listbox is the listbox which i use to take items from my produktlist and put it in my checkout "basket" then i am suposed to be able to choose one of these items from my checkout basket put the amount i want of that item into a textfield called KvantLEv and press the checkout button to be able to simulate a checkout and then this selected item's quantity is suposed to be lowerd by the specified amount and is to be removed from the checkoutlistbox but this aint working... this is my checkout function so far
private void cashout()
{
produkt p = new produkt();
int a = VaruKorg.Items.Count - 1;
[Code]....
View 7 Replies
View Related
May 16, 2013
Error:
--------------------Configuration: nc - Win32 Debug--------------------
Compiling...
cv.cpp
Linking...
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/nc.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
nc.exe - 2 error(s), 0 warning(s)
Compiles with 0 error but on running 2 Errors appear.
I'm Inputting data of an object from user and then inserting it in the link list.
#include <iostream>
//#include <fstream>
using namespace std;
#define LEN 100
////////////////////////////////////////////////////////////////////////////////////////////////////
class employee{
[Code] ....
View 1 Replies
View Related
Apr 19, 2013
I have a list of objects that I need to read information from each object to compare to a user input prompt.
#include "Passenger.h"
#include "Reservation.h"
#include "Aircraft.h"
#include <iostream>
#include <fstream>
#include <string>
#include <list>
using namespace std;
//Function Prototypes
void flightRoster(list<Reservation>&);
[Code] ....
View 1 Replies
View Related
Feb 2, 2015
I have a question similar to the one here: [URL] .....
The main difference is I would like to pass a method of derived class as a parameter to some other method in its template base class.
template <typename BaseType>
class Base {
public:
typedef void (Base::*Callback)(int A);
[Code] .....
The above is an example which does not compile. My compiler complains that the two BaseMethod() calls in DerivedMethod() are invalid uses of non-static member function.
Is this not possible to do, or is my syntax simply wrong? All I want is to be able to pass as an an argument to a method in the base class from the derived class some callback as a variable for the base class to invoke later.
View 2 Replies
View Related
Apr 27, 2013
Here is a function,which deletes the spaces of a string...
char *removespaces(char *s1) {
Code: char *s2=s1;
int i,j=0;
for (i = 0; i<strlen(s1); i++){
if (s1[i]!=' ') {
s2[j]=s1[i];
[Code] .....
why I have to initialize the pointer *s2 with the first element of the array s1...???If I don't initialize the pointer,or initialize it with something else,I get a segmentation fault...
View 10 Replies
View Related
Apr 28, 2013
I would like to initialize an arry containing function pointers with adresses of functions that have a variable number of arguments.
Below the code that works in principle. I would however get rid of the warning message during compilation pointing to the initialzation of the funtion pointers in the array. How do I need to cast the pointers to the functions ?
Code:
gcc func_ptr_init.c
func_ptr_init.c:28: warning: initialization from incompatible pointer type
func_ptr_init.c:32: warning: initialization from incompatible pointer type
Code:
#include<stdio.h>
unsigned char func1_ptr(unsigned int* if_desc, int* result_code) {
*if_desc = 1;
*result_code = 1;
return(0);
[Code] ....
View 8 Replies
View Related
Apr 4, 2014
In a book I'm reading, the author has the following struct:
struct VertexPos {
XMFLOAT3 pos;
};
Where XMFLOAT3 is a structure with x,y,z floating point values within. He declares and initializes an array as the following.
VertexPos vertices[] =
{
XMFLOAT3(0.5f, 0.5f, 0.5f),
XMFLOAT3(3.3f, 5.6f, 3.6f),
XMFLOAT3(-4.5f, 2.2f, 6.4f)
};
It doesn't make sense to me why this is working. The way my mind is thinking about this is that vertices is an array of type VertexPos, so then why can it be initialized with objects of type XMFLOAT3?
View 2 Replies
View Related
Nov 17, 2014
I have a class containing a map member that I want to initialize at declaration time. I know I can do it in the cpp file but I'm having a problem with the order of initialization (static initialization order fiasco).
My questions are:
Is it possible that the scenario in which, the Test's constructor's implementation and the map initialization instruction are in the same cpp file and constructor is called when the map is not initialized yet, could happen?
Is it possible to initialize the map in class like I did? I get these errors:
in-class initialization of static data member 'std::map<std::basic_string<char>, Test*> Test::a' of incomplete type
temporary of non-literal type 'std::map<std::basic_string<char>, Test*>' in a constant expression
If yes, does this initialization resolve the static initialization order fiasco?
class Test {
public:
static std::map<std::string, Test*> a = {};//this is an error
Test(std::string ID) {
[Code] ....
View 4 Replies
View Related