Visual C++ :: Vendor Classes - Conflicting Declaration Of Objects

Jan 22, 2013

The Light and Fan are two different vendor classes and they are not derived from any base class. I am trying to implement the Command design pattern but with generic implementation, so it should work in future with any new vendor class like Door, Window etc without much change in client code. I have thought about a Factory method but it will not work because it needs a Base class. I am trying to learn the design patterns.

Light *myobj;
Fan *myobj;
int choice;
cout<<"Select Light (1): ";
cout<<"Select Fan (2): ";

[Code] ....

Error:conflicting declaration 'Fan*myobj'

View 14 Replies


ADVERTISEMENT

C++ :: Declaration Of Template Specialized Classes

Aug 12, 2014

class intClass{};
class stringClass{};

template <typename T>
class Mediator {
// bunch of code
};

I want Mediator<int> to declare intClass friend, Mediator<std::string> to declare stringClass friend etc..., without having to redefine the entire specialization

template<>
Mediator<int>::friend intClass;

View 5 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# :: Getting Properties From Different Classes / Objects

Feb 26, 2015

I have startes making a game where there is 3 ships that cross the screen verticaly, and the point is to shoot them down. So far I have actually managed to do this. I have also managed to add gamescore to the ships. But here is my problem, I cant find a way to combine the score from all three ships in to one score. I have all three ships in different classes, is that wrong? When I try to combine the scores, ship score1 cant see the other scores.

Do I need to somehow have all the ships in one class. Or are there a way to read the scores from three classes, and adding them up in to one in a new class?

One of the errors I get is "the name 'score1' does not exist in the current context.

View 14 Replies View Related

C# :: How To Define Objects Within Classes

Oct 7, 2014

When are you creating fields/properties for specific classes and when you are not doing it but creating them inside just lets say straightaway inside some methods within that classes. I mean if i got class where inside i want to create instance of some other class and then pass this instance to another class - should i create a field for it within class i am doing this operation or not? I was always reading that you create field/properties when its belong to class itself. So if i want only to create some instance outside class i am working and pass it to other class and this is not exactly the part of this class shouldnt i create a field for it and just create it inside method?

View 5 Replies View Related

C++ :: Objects / Classes And Separate Compilation

Apr 9, 2013

Code:
class A
{
public:A(int a, int b);
};

I need to have an object of class A that doesn't have a default constructor in another class, B:

Code:
class A; //This is in a separate header file
class B
{
private:A a;};

The problem is that it won't compile without a default constructor. I'm not allowed to define a default constructor, and the A object in class B has to be private so I can't initialize A a in public.

I also can't change the prototype in the interface to something like

A(int a = 0, int b = 0);

since one of the requirements is that if an object of class A is declared in main, it must not compile due to not having a default constructor. So what can I do to make class B work and compile?

Another question I have is why is this valid:

Code:
class A; //#include "A.h" is in the implementation file so it compiles.
class B
{
private:A* a;}; But not this: Code: class A;

class B
{
private:A a;};

This is for a project that I probably won't be able to turn in on time, but I care more about how to do this right than turning it in for full points.

View 4 Replies View Related

C# :: Generating Objects Via Arrays From Classes

Jun 26, 2014

Here's the problem. I want to generate an array of objects from classes.

brick[] tile = new brick[5] // originally wanted an array of 500 to play with but I thought I'd start small first

I wanted to make a draw() function in my "level01" class to generate a map (so I wouldn't have to build them in photoshop then manipulate rectangle bounding boxes). I tried several things...

First, I found a thread that worked to get rid of the null value in the array ("not set to reference of an object" error).

After that, within a for loop, I tried to initiate my values...

for (int i=0; i < tile.Length; i++) {
tile[i] = new brick(); // calling the object
piece[i] = new PictureBox(); // calling the object's container
//tile[i].brick1X = 38; // already had a default set to it so I commented this out to see if it made
// any difference... it didn't
tile[i].brick1Y += 32; // if this worked, it would have drawn a 32x32 tile down the Y axis every 32
// pixels

[Code] ....

In my Form.cs, I declared my first level map as:
level01 L01 = new level01();

Under the form's constructor, I instructed it to
L01.draw();
so that it would initiate on the game screen.

Needless to say, I get the game screen and the frame, the menu bar I have pops up. But, no tiles.

I even went so far as to get rid of the null values for [i] in the array (using the above for loop but with fewer tasks within the loop) and created a counter that would count up += 1 every time it would make an object.

if (counter < 5) {

And would put in the above tasks inside of the logic loop. I would either get nothing drawn on the screen or it would throw an exception.

I could easily make this using XNA Game Studio in Visual Studio 2010 but I'm using VS2013 and wanted to do a program straight in C# instead of using XNA.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
using System.Windows.Forms;

[Code] ....

View 4 Replies View Related

C++ :: Create Inventory System Using Classes And Objects?

Jan 13, 2015

I'm trying to create an inventory system in C++ using classes and objects. Here is what I have now

Item.h

#pragma once
#include <iostream>
#include <allegro5/allegro.h>
#include <allegro5/allegro_image.h>

[Code]....

Basically what I want my inventory system to become is this: [URL] Each slot can hold an item.

Basically this inventory system should be able to do what RS Inventory system can do. (Hold items, Use items, Equip Items (No need for moving item))

View 5 Replies View Related

C++ :: Creating A Game - Use Classes For Rendering Objects?

Mar 16, 2014

I am creating a game and I using classes for other things in my game, I was wondering if i should use classes for rendering objects?

View 2 Replies View Related

C++ :: Stuck On Student Project / Classes And Objects

Aug 28, 2014

Working on a project for a c++ class and got a bit stuck.

What I am trying to do is include a class for calculating home square footage in a program I have written for my last project. When I do this, I get errors in codeblocks, on lines 74 and 87, "expected ; before 'box', and 'box' was not declared, respectively. Unsure what my snafu is... I had these two programs separate and both run without errors until I combine the two into one program.

View 2 Replies View Related

C++ :: Read In Name Of A Vendor Into Array Of Structures

Feb 26, 2013

so im trying to read in the name of a vendor into an array of structures. and write the name into a file.

#include <iostream>
#include <cstring>
#include <cctype>
#include <fstream>
using namespace std;
struct booth

[code]....

View 5 Replies View Related

C Sharp :: Retrieving USB Pendrive Vendor ID / Product ID And Serial Number

Sep 15, 2012

I am trying to retrieve the parameters from externally connected pendrive. I have been using WMI to achieve this but not able to separate the pendrive's parameters from the other USB devices (such as USBcamera,USBHub etc) ....

View 2 Replies View Related

C :: Conflicting Types Error When Compiling A Lib

Dec 24, 2014

I'm trying to compile a library for use with PoLabs Pokeys 56U USB device (PoKeys56U) on Linux Mint 17 64-bit.

I'm using the information from here - New cross-platform library for all PoKeys devices - MyPokeys

When I run

sudo make -f Makefile.noqmake install

I get the following errors;In file included from PoKeysLibCore.c:22:0:

PoKeysLib.h:38:28: error: conflicting types for "int64_t"
typedef long long int64_t;
^
In file included from /usr/include/stdlib.h:314:0,
from PoKeysLibCore.c:21:

[Code] ....

Here is the offending code from the header file;

Code:
#ifndef __POKEYSLIB
#define __POKEYSLIB
#define USE_STD_INT

#ifdef USE_STD_INT
#include "stdint.h"

[Code] ....

View 12 Replies View Related

Visual C++ :: Unfamiliar Function Declaration

Dec 31, 2014

I am experimenting with the c++11 regex and came across an item missing from my limited c++ knowledge.

From this article: [URL] ....

I am unfamiliar with this function with the -> operator?

Code:
auto begin(strip const & s) -> char const *
{
return s.first;
}

Is this code the same?

Code:
char const* begin (strip const& s) {
return s.first;
}

View 3 Replies View Related

C :: Calculate Distance Between Two Latitude And Longitude Points - Conflicting Types For Function

Mar 6, 2015

In my project i need to calculate the distance between two lattitude and longitude points. After compiling the code I am getting an error that "conflicting types for deg2rad". How to solve this? Seems the code looks ok. but...

Code:
#include <math.h>
#define pi 3.14159265358979323846
double distance(double lat1, double lon1, double lat2, double lon2, char unit) {
double theta, dist;

[Code] .....

View 4 Replies View Related

Visual C++ :: Include Object From Another ATL COM DLL - Employee Classes?

Nov 7, 2014

This refers to an ATL COM DLL project. I can successfully create a class hierarchy of objects, ie. say, one class is the TEAM, which then holds other objects, say, a leader and a secretary, both of which are Employee Classes . Here goes my question:

a) In the Team.h header file I declare m_pLeader as a CComPtr<IEmployee>

Code:
classATL_NO_VTABLE CTeam :
public CComObjectRootEx<CComSingleThreadModel>,
public CComCoClass<CTeam, &CLSID_Team>,
public IDispatchImpl<ITeam, &IID_ITeam, &LIBID_BUOBJ05Lib, /*wMajor =*/ 1, /*wMinor =*/ 0>
{
private:
CComPtr<IEmployee> m_pLeader;
CComPtr<IEmployee> m_pSecretary;

b) The Employee Class is defined within this ATL COM project.
c) In the Team.cpp file, I create an instance in the FinalConstruct code, the focus is on the CEmployee

Code:
HRESULT CTeam::FinalConstruct(){
CComObject<CEmployee>* pLeader;
HRESULT hr=CComObject<CEmployee>::CreateInstance(&pLeader);
if (FAILED(hr))
return hr;
m_pLeader=pLeader;
// ..same for secretary...
return S_OK
}

d) Here comes my QUESTION: How must I proceed if the Employee object was part of another ATL COM DLL, that is it would be described in another DLL that I would now like to reuse? I guess I need to

1. Have the other DLL's idl-, tlb, and h file in my project folder. Let me name it "other.h, other.idl, other.tlb"

2. Both h- and cpp-file must have an #include "other.h" statement -- please correct if I am wrong..

3. ...but how must in the Team's h- and cpp-files the statements be (assuming the class in the "other" Dll is Member (instead of Employee? I know the following code will NOT work, so I am asking how it should be correctly?

Code:
private:
CComPtr<IMember> m_pLeader;

4. and in cpp file for:

Code:
CComObject<CMember>* pLeader;
HRESULT hr=CComObject<CMember>::CreateInstance(&pLeader);
[/code]

View 10 Replies View Related

Visual C++ :: Implementing Classes And Creating Driver Function?

Nov 30, 2012

I'm am having a few issues with this program, they stem from passing the color.h and .cpp into another .h and .cpp, and frankly getting how those two things really fit together.

For this problem, you will design and implement 2 classes and then write a driver function to test these classes. The first will be a C++ class for an abstract data type color with a public enumeration type colorType that has the color values shown in Listing 10.8. Your abstract data type should have an attribute for storing a single value of type colortype and member functions for reading (readColor) and writing (writeColor) a color value as well as setting and accessing it. The function readColor should read a color as a string and store the corresponding color value in the value attribute of a type color object. The function writeColor should display as a string the value stored in the value attribute of a type color object (see Figure 7.5). Modify class circle and the driver function in Listing 10.9 to include and use this class. You'll need to remove the declaration for color in class circle. Test your modified driver function with the new color and circle classes.

The second class will be to design and implement a rectangle class similar to class circle. Be sure to incorporate the new color class you have written and tested in the first part of the programming exercise. Write a client program that asks the user to enter a shape name (circle or rectangle) and then asks the user for the necessary data for an object of that class. The program should create the object and display all its attributes.

The circle class .h and .cpp files as well as the original driver function will be supplied. You are to provide the .h and .cpp files for the new color class and the modified driver function as well as the .h and .cpp files for the rectangle class and the client program that uses all three classes.

color.h

Code:

//color.h
//Color class definition
#include "stdafx.h"
#ifndef COLOR_H

[Code].....

View 3 Replies View Related

Visual C++ :: Friend Classes In Separate Header Files?

Nov 25, 2012

I am struggling to enable friendship between two classes in separate header files for a banking program.

I am attempting to get the Person class to use variables from the Account class. Heres what I have so far.

ACCOUNT.h:

Code:
#include<iostream>
#include<fstream>
#include<cctype>
#include<iomanip>
#include <string>
#include <math.h>
#include <windows.h>
#include <vector>
#include "Person.h"
using namespace std;
class person;

[code].....

View 3 Replies View Related

Visual C++ :: Destroying CArray Of Cobject Derived Classes

Nov 21, 2013

I use a CArray<CClase1,CClase1> m_Clases1.

CClase1 is derived of CObject. " class CClase1 : public CObject"

When, at last I do : "m_Clases1.RemoveAll()" , I suppose that the CClase1 destructor is called. But when i do this the program fails.

View 6 Replies View Related

Visual C++ :: Synchronization Objects In MFC?

Jul 16, 2013

I want to understand synchronization objects in MFC in detail. I want to understand Mutex / Semaphores / Events / Critical Section in detail....How to use implement and use in practical examples.

View 12 Replies View Related

C :: Parameter Names Without Types And Conflicting Types In Fgets

Jan 22, 2014

I have this

Code:

#include<stdio.h>
#include<ctype.h>
#include<string.h>

int check_up(char string[]);
int check_low(char string[]);
void to_up(char string[]);
void to_low(char string[]);

[Code] .....

When I compile this I have the following problems: warning: data definition has no type or storage class [enabled by default] in 'to_up(word)'conflicting types in 'to_up' function and to_low function warning: data definition has no type or storage class [enabled by default] into_up function error: unknown type name "word" in line 'printf("All uppercase %s. ", word):;'warning: parameter names (without types) in function declaration [enabled by default] in 'to_up(word)'and 'to_low(word)' 'note: previous declaration of "to_up" was here in function declaration of to_up function

View 7 Replies View Related

Visual C++ :: Initialize Constructor In Array Of Objects?

Oct 28, 2012

What the best way to initialize a constructor in an array of objects?

Usually I declare an array of objects like so:

Code:
Car toyota[100];

Is this the only way I know to initialize a constructor of an array:

Code:
for (int i = 0; i < 100; i++)
{
toyota[i] = Car(x, y);
}

Is this the proper way?

View 1 Replies View Related

C++ :: Array Of Classes With Classes Inside

Oct 5, 2013

I have an array of (Student)classes created in Manager.h, which contains a new instance of class Name (name),(in Student.h)How would I go about accessing the SetFirstName method in Name.cpp if I was in a class Manager.cpp? I have tried using Students[i].name.SetFirstName("name");

// In Manager.h
#include"Student.h"
class Manager
{

[Code]....

View 2 Replies View Related

Visual C++ :: How To Order Records In ACCESS By MFC Objects Like CDaodatabase Or CDaoRecordset

Dec 13, 2012

Table with primary key already set-down in ACCESS. when insert records into the table by Execute() function of cdaodatabase, to some extense, the records are not put behind the last record as wished, otherwise randomly into other places!

now i want to do some kind of operation to order the table after insertion by cdaodatabase or some others. how to?

View 4 Replies View Related

Visual C++ :: Design Class Objects To Support Outlining Of Collection Of Items

Sep 9, 2013

I am struggling with how to efficiently design my class objects to support the outlining of a collection of items. The collection would be sorted but would also have the ability to indent and outdent individual items representing a Parent and Child relationship (see attached).

An item could indent up to 5 levels deep. A summary level would be considered a Parent while items below the summary level would be consider as children.

View 6 Replies View Related

C/C++ :: Objects Hold References To Other Objects?

Nov 12, 2014

This has been bothering me for a while now, and I finally put together an example:

#include <iostream>
#include <string>
using namespace::std;

[Code]....

In the code above, the two classes hold pointers to each other, and that's fine but it doesn't seem right since C++ prefers to pass by reference. Yes, it can still do that (see testbox and testball) but even that seems odd to me because still you need to use pointer notation for the enclosed object. Am I the only one who feels this way, and should I just get over it? Or am I missing something that would allow an object to hold a reference?

View 4 Replies View Related







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