C# :: Determinate Type Of Object And Pass It Through Method

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


ADVERTISEMENT

C++ :: Object Type Method Return

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

C++ :: Pass Double Pointer Of Object Into A Node Of Self Similar Type?

Nov 30, 2014

The following code compiles and runs fine till it reaches line 16 and gets a sigsev violation which I'm not sure about as to why. I have no problem passing the object of type node** into the constructor of base and storing it into the double pointer node** copy;; but when I call the function void pass(node** temp) it crashes.

#include <iostream>
class base;
class node {
private:
node** data;
public:

[Code] .....

View 3 Replies View Related

C++ :: Pass Method Of Derived Class As Parameter To Another Method In Base Class?

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

C# :: Method Is Overwriting Both Instance Of Object And Original Object

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

C++ :: Object Method Does Not Respond

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

C++ :: New Data Type In Method Declaration?

May 26, 2013

I want my method of the class to take as an input an array of data type derived from class. How can I do this?

Code:
class Planet {
public:
// typedef class Planet PlanetType;
void GetForce(int, PlanetType []);
};

Or when should I define my new data type PlanetType?

View 14 Replies View Related

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 View Related

C++ :: Trying To Pass Array Of Object

Apr 24, 2013

I am trying to pass an array of objects however i m finding some problems.

pieces.h

Code: class Cpiece{
public:
Cpiece* board[8][8];// array of objects
virtual char getcolor() =0;
virtual char setcolor(char colour)=0;

[Code] .....

View 10 Replies View Related

C/C++ :: Pass Value From Object To Array

Apr 16, 2014

I am trying to write a poker program. I created a class to create a deck of cards..and then shuffle the deck..Now I am trying to pass value from the deck to an array to deal a hand..so 5 cards to player1[] array.. I tried doing it directly such as.

for (int j = 0; j < 5; j++) {
getCard=deck[j].toString();
}

But I would get error such as [Error] no match for 'operator=' in 'player1[j] = deck[j].Card::toString()'

So then I tried using a pointer..

char *getCard;
getCard = new char;
for (int j = 0; j < 5; j++) {
getCard=deck[j].toString();
}

but I would get this error [Error] void value not ignored as it ought to be. So how can I pass a value from the object deck..to an array? or should I be doing it another way?..I tried to think of a way to do it via a function but really got hung up there..

here is full code

#include <stdlib.h>
#include <iostream>
#include <ctime>
#include <algorithm>
using namespace std;
const char* FaceString[13] = {"Ace", "2", "3", "4",
"5", "6", "7", "8",
"9", "10", "Jack", "Queen", "King"};

[Code] ....

View 11 Replies View Related

C++ :: Pass Object As A Pointer In Function

Apr 12, 2013

i need to pass myboard.board (board is in the class Cboard and it is an array of int) to a function in a class called piece however this is troubling . i need to pass it as pointer os that i could change its value here under is my code.

main.cpp Code: #include<iostream>
#include"board.h"
#include "pieces.h"

[Code].....

View 7 Replies View Related

C++ :: Pass Class Object By Reference

Jun 25, 2013

I am having trouble working with third party dll's, libs and header files. I am trying to call a function.here is the function that is suppose to be called.

bool COAuthSDK::GetRequestToken(CClientDetails &objClientDetails)

it has this info of what it needs :

Name IN/OUT Description
m_environment IN Optional. Possible values are SANDBOX (default) and LIVE.
m_strConsumerKey IN OAuth consumer key provided by E*TRADE
m_strConsumerSecret IN OAuth consumer secret provided by E*TRADE
m_strToken OUT Returned by the function if successful
m_strTokenSecret OUT Returned by the function if successful
m_strCallback IN Optional; default value is "oob"

here is the COAuthSDK header

#ifndef _OAUTHSDK_H_INCLUDED_
#define _OAUTHSDK_H_INCLUDED_
#include "ETCOMMONCommonDefs.h"
#include "ETCOMMONOAuthHelper.h"
using namespace std;

[code].....

when I try to build the function it says that its in the dll's so I know I have to call it.here is the link to the build site if needed URL....

View 1 Replies View Related

C++ :: Pass Class Object By Reference?

Mar 17, 2014

I'm trying to pass a class object by reference.

total = mathfunction(i);
}
double mathfunction(retirement& j)
{
double R = 0.00, m = 0.00, r = 0.00, t = 0.00, totaled = 0.00,
numerator = 0.00, denom = 0.00, temp = 0.00;

[Code]....

I only tried to pass by reference because I figured passing by value would be a larger pain in the neck.

View 1 Replies View Related

C++ :: How To Pass Same Instance Of Object In Two Functions

Feb 25, 2014

I need to send same instance of object of a class in two function (Main function and thread function). The class is something like this:

//The class need to have constructor.
Class ABC {
public:
DWORD *IdG;
ABC(int number) {
IdG = new DWORD[number];
}
}obj(32);

The obj(32) is called in following two function. Function F1 is called using thread in main function.

void F1() {
obj.test;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) {
obj.test1;
_beginthread(F1,0,(void*)number);
}

The code works well when the object of class ABC is created as shown above. My problem is the value that is passed in the object ('32') is to be read from the file.

If I read the file and create object separately in Main function and function 'F1' then , function 'F1' is not executed.

How to create same instance of object for Main function and function 'F1' with value passed in the object taken from the file.

View 1 Replies View Related

C/C++ :: Maximum Divisor Sum - Determinate Number Between 2 And N

Oct 17, 2014

The problem says that i have a number n > 0 and the program should determinate the number between 2 and N who has the maximum divisor sum (1 and N wont count as divisor). If i have more numbers with maximum divisor sum, should wrote only first number. Exemple: for N = 100 , will show 96 bcoz he has the maximum divisor sum, which is 155. For the start i tried to show only the maximum divisor sum, not the number who has the maximum divisor sum with this code:

#include<stdio.h>
int main() {
int n,s=0,i,m;
printf("Please introduce the number N > 0:");
scanf("%d", &n);
i = 2;

[Code] .....

And it shows me 116, but the correct results is 155. Which is the problem ?

View 4 Replies View Related

C++ :: Template Method Based On The Type Passed Should Return A Value

Mar 8, 2014

I have a class where a method based on the type passed I should return a value.

prototype declared in the header file:

template <typename T>int getNum() const;

Code of the cpp file:

template <typename T> int class::getNum() const{
int c = 0;
for(int i=0;i<v.size();i++)
if(typeid(*(Pro*)v.at(i)) == typeid(T)) c++;
return c;
}

To invoke the method as I do:

ostream & operator << (ostream & os, Pro & obj) {
return os << obj.getNum();
}

View 4 Replies View Related

C Sharp :: Use Return Type Bool In WEB API Post Method?

Oct 3, 2012

I sew lot of sample for ASP WEB API. In althose link the post method is using

HttpResponseMessage as return tyope

Is it possible to use return type bool in WEB API post method?

View 1 Replies View Related

C# :: How To Pass Bitmap Data Type To DLL

Jun 24, 2014

C# Code

[DllImport("dllTestForm.dll", EntryPoint = "showFormC")]
static extern void testShowFormC(byte[] photo,int len);
private void button6_Click(object sender, EventArgs e) {
Bitmap bmp = (Bitmap)Image.FromFile(@"d:11.jpg");
Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height);

[Code] ....

The program has no tip errors ,But there is no any picture display in c++ form,Tested the simple data types, such as int, can be normal .

View 1 Replies View Related

C++ :: Unable To Pass Reference Of Object Ifstream To Constructor

Jan 30, 2013

I'm trying to pass an reference of the object ifstream to my constructor as such:

// myClass.cpp
int main(){
ifstream file;
myClass classobj = myClass(file);}

I am defining the constructor as follows, in myClass.cpp:

myClass::myClass(ifstream &file){
// do stuff
}

I get the error of "No overloaded function of myClass::myClass matches the specified type."

Also, when I build the program, it tells me "syntax error: identifier 'ifstream'"

Also, I made sure I included this:
#include <iostream>
#include <fstream>
#include <sstream>

What am I doing wrong? How can I pass an ifstream reference to my constructor?

View 3 Replies View Related

C++ :: Declare Template Type Object Inside Template Type Class Definition

Oct 12, 2013

Let me put it into the code snippet:

/**
This class build the singleton design pattern.
Here you have full control over construction and deconstruction of the object.
*/
template<class T>
class Singleton

[Code]....

I am getting error at the assertion points when i call to the class as follows:

osgOpenCL::Context *cxt = osgOpenCL::Singleton<osgOpenCL::Context>::getPtr();

I tried commenting assertion statements and then the debugger just exits at the point where getPtr() is called.

View 7 Replies View Related

C++ :: Pass Object To Class Which Stores It In Container As Unique Pointer

Jul 24, 2013

class A (abstract)
class B : A
class C {
void add ( A(&*?) a )
std::vector<std::unique_ptr<A>> data; //unique_ptr<A> because A is abstract and therefore vector<A> isn't possible
}

upper situation. What is the best way to pass add an object of class B to C?

with C::add(A* a){ vector.push_back( unique_ptr<A>(a) ); }
and
int main() {
C c;
c.add( new B() );
}

This works, but i don't think it's very nice, because you could delete the pointer in main. What happens then with the unique_ptr? I could probably make C::add( std::unique_ptr<A> u_p ); but maybe it can be avoided that the "user" (in main() ) has to create the unique_ptr itself.

View 10 Replies View Related

C++ :: Getting A Type From Object

Apr 20, 2013

it is not possible to get a type from an object, only from a type. Even with auto, you can only instantiate another type of the same type.I'd like to get a type from an object given another type, mainly because it is less typing and less error prone.

Some psudocode:

Type1 A<X, Y> a;
int b;
Type2 a.InnerType<b>::type c; // obviously won't work

A work around I thought of would be to use functions:

Type1 A<X, Y> a;
int b;
auto c = a.getInnerType(b);

Which is kinda interesting and looks like the way I'm going to go. However, I'm just wondering if there is any other ways of doing this as I don't really want to instantiate an object if I can avoid it (though the optimizer will probably just dump it anyway).

View 2 Replies View Related

C++ :: Derive Type From Object?

Aug 9, 2012

Suppose I'm wanting to define a predicate for some algorithm. I already need to provide the begin/end iterators of a container, can I somehow use the container instance to derive it's type that I can then use as parameters of the lambda predicate ?

Essentially... something along the line of:

Code:
// doesn't compile ! just used as an example
auto something = std::min_element( foo.begin(), foo.end(), [](typeof(foo)::const-reference left, typeof(foo)::const_reference right) {
left.calculateSomething() < right.calculateSomething();
});

Essentially, I don't care about what specific type is stored in foo. I just want a convenient way to get to the type without having to look up that the actual type is :

mynamespace::somebaseclass<templatevar1,templatevar2>::somenestedclass<templatevar1>::value_type

View 5 Replies View Related

C++ :: Initializing Generic Type That Can Be Both Primitive And Object?

Apr 1, 2013

I have defined my own class, Queue, which inherits from my own class, LinkedList. I have been using templates to allow Queues to be of int, string, etc types.

But now I want to be able to store objects in my Queue type. And so the problem I have is that in my LinkedList class, I have two instances where I initialize an instance of my generic type T to 0.

For instance, the removeFirst() method starts like this:

template <typename T>
T LinkedList<T>::removeFirst() {
T a = 0;

And so the compiler complains that it can't convert from int to [in this case] Command&.

What to do?

View 2 Replies View Related

C++ :: Object And Classes - Declaration Of Variable Using User Defined Type

Mar 17, 2013

I am getting a compilation error from the code below. It is when i am naming a variable with my user defined type.

#include<iostream>
#include<cstring>
#include<cstdlib>
using namespace std;
class person {

[Code] .....

C:Dev-CppTRIAL.PASS.!!!.cpp In function `int main()':
66 C:Dev-CppTRIAL.PASS.!!!.cpp expected primary-expression before "p"
66 C:Dev-CppTRIAL.PASS.!!!.cpp expected `;' before "p"
74 C:Dev-CppTRIAL.PASS.!!!.cpp `p' undeclared (first use this function)
(Each undeclared identifier is reported only once for each function it appears in.)
83 C:Dev-CppTRIAL.PASS.!!!.cpp `X' undeclared (first use this function)

View 4 Replies View Related

C++ :: Retrieving File Object From Function Then Pass To Another Function?

Jun 27, 2014

I would like to have 2 functions. (FYI, I haven't even tested these because I don't have a compiler on this PC, so don't know what they'll do. I'm also new to C++, self-teaching.)

My question is, I'm sure that oFile should be type object (of some sort), not int, but I'm not sure how to reference it correctly so that it passes from FileOpen to main to FileClose.

Code:
#include <iostream> //I/O
using namespace std;
#include <fstream> //files
using namespace ios;
int FileOpen(string fileName) {
ifstream oFile (fileName); //attempt to open file

[Code] ....

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved