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.
So I have 2 seperate base classes, (note that I removed the variables and functions that do not relate to the topic) Object.h
class Object{ public: Object(); ~Object();
[Code].....
The error I get is saying I am calling a function declared with one calling convention with a function pointer declared with a different calling convention and this makes perfect sense because for some reason, the function pointer is pointed at the virtual function Object::update but I can't figure out why and how to make it point at the virtual function Drawable::getImage.
Also, the virtual update function is called in a different place just before this and works correctly.
#include<iostream> #include<string> using namespace std; //Constructors for class. class CollegeCourse { private: int courseNum;
[Code] ....
When I debug my program, the objects is showing up on one line bunched up together. I also want to be able to enter data after each object of the classes.
The details of my project is as follows:
Inheritance in C++ means you can create classes that derive their attributes from existing Classes, in other words, a newly created class can absorb all the data fields and functions of a class already being used. When one class is derived from another, the original class is the parent class, base class, or sometimes called the parent class. The derived class is a child class, or sometimes called the subclass.
Inheritance is central to Object Oriented Programming. The advantages of inheritance are it allows the code to be reused as many times as needed. Inheritance also saves time and effort as the main code need not be written again.
Create a C++ program using Visual program that could be used by a college to track its courses. In this program, create a CollegeCourse class includes fields representing department, course number, credit hours, and tuition. Create a child (sub class) class named LabCourse, that inherits all fields from the CollegeCourse class, includes one more field that holds a lab fee charged in addition to the tuition. Create appropriate functions for these classes, and write a main() function that instantiates and uses objects of each class.
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.
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?
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;
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.
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): ";
i am just making some new programmings and testing it. But every time after compile and run The dos window is closing and again I have to compile And run command so i want The dos windows should prompt me for next input rather than closing.
I am working on one application that requires extensive logging so I want to create a log file of each day during execution.
I tried easylogging++ but i am unable to use into multiple files. If i try to use in other file. I get compilation errors of using same functions or methods already defined.
How can i use macro to hide the implementation of logging in one class to other ??
I've been writing a game engine in C++ for a little over a year now, and its been really fun so far. I've been focusing on windows support for now (using Visual Studio and MSVC) but I'd like to leave the possibility of Linux and Mac support open. As a test, I recently compiled a small portion of my reflection system in Clang, to make sure it all still worked (since I consider that the most advanced portion of my codebase, though I'm pretty sure its all standard C++11). Anyway, I got some strange errors regarding undefined identifiers in template functions, and I managed to isolate the issue in the code below:
Clang throws an error about 'TypeInfo' being undefined when 'DoSomething()' is compiled. However, MSVC compiles the code above without so much as a warning.
This goes against my understanding of how template functions/classes were compiled. I always thought that Undefined symbols were not an issue in templates, as long as they were defined by the time the template was instantiated. Whats the issue here? If in fact MSVC has been doing some non-standard stuff, that's pretty unfortunate for me if I want Linux support, as I'll have to do some serious backflips to resolve all the issues with this in my headers and stuff (I can't be the only one in thinking the current state of C++ with headers and forward-decelerations is just awful to work with).
I want to do conditional compilation based on whether it is windows 7 or windows 8. Here is the code below.
#if (_WIN32_WINNT >= 0x0602) //Condition to check whether it windows 7 or 8 .Based on this we can load msxml 3 or 6. #import <msxml6.dll> #else #import <msxml3.dll> #endif
Im building the above code in windows 8 machine.
Issue here is _WIN32_WINNT should have a value 0x0602, it means it is running in windows 8 machine.Instead it has a value 0x0601 (Means it is taking windows version as windows 7 defined in sdkddkver.h).Im not sure after installing windows 8 sdk im not able to see any include or lib files in the path below C:Program Files (x86)Microsoft SDKsWindowsv8.0A . but i can see all include and lib files of sdk version v7.0A available although i did not installed it.
This is my question : Define a class named HOUSING in C++ with the following descriptions:
Private members REG_NO integer(Ranges 10 - 1000) NAME Array of characters(String) TYPE Character COST Float
Public Members -Function Read_Data( ) to read an object of HOUSING type -Function Display() to display the details of an object -Function Draw Nos( ) to choose and display the details of 2 houses selected randomly from an array of 10 objects of type HOUSING Use random function to generate the registration nos. to match with REGNO from the array.
Now I' trying to do this by this way
Code: #include <iostream.h> #include <conio.h> #include <stdlib.h> class housing { private: int REG_NO; char NAME[10];
[Code] .....
I am trying to pass the entire array of object in DrawNos(). but getting compilation error -
32: 'housing:rawNos(housing * *)' is not a member of 'housing' 48: Structure required on left side of . or .*
What is the problem? How can I pass the array of object in function and use it.
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 {
Today I experienced a very strange compiler issue. I started the compilation and it outputted that a member object of a class was undefined. After about 4 hours of trying the find the bug I commented and then uncommented said line of code that was undefined. Sure enough the compilation worked just from commenting and uncommenting.
I am using Microsoft visual studio 2012 express. Due to the size of the project, I should know the cause because it may cause more problems further down the line. I feel that it might have something to do with the compiler not having a proper order of compilation for the header files and that I might need something to solidify the way that the header files are processed. The below code is a fragment of a header file.
I'm parsing a text file, and I'd like to detect when a certain Compilation Condition - i.e. #ifdef - begins. The challenge is, that the condition can take any of the following patterns:
#ifdef (FLAG) #if defined (FLAG) #if (defined (FLAG))
(And perhaps I missed more)
I'd of course need to treat them all the same, as they are indeed the same. How would you know to treat them all the same?
I am trying to write a generic linked list in c, but for some reason i keep getting errors saying "incompatible pointer type. This is the code and erros:
#include <stdio.h> main() { int c, n1; n1 = 0; while ((c = getchar()) != EOF) if (c == '') ++n1; printf("%d", n1); }
I have a more complicated program I'm wishing to have display the output, however, to save some time I'm using an example of a shorter version. count the lines in input and display the output in terminal when ./program is executed after compilation. To count and compute lines, words and within arrays.
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?