-
-
#include <iostream>
-
using namespace std;
-
template <class T>class list{
-
protected:
-
typedef struct node{
-
node* prev;
-
T* data;
-
node* next;
-
};
-
node* first;
-
node* last;
-
public:
-
list();
-
void push_back(T& t);
-
void pop_back();
-
T& front();
-
T& back();
-
node& end();
-
node& begin();
-
void print_list();
-
};
-
template <class T>
-
list<T>::list(){
-
first=0;
-
last=0;
-
};
-
template <class T>
-
T& list<T>::back(){
-
return last->data;
-
}
-
template <class T>
-
T& list<T>::front(){
-
return first->data;
-
};
-
template <class T>
-
list<T>::node& list<T>::end(){ //error in this line.
-
return *last;
-
}
-
template <class T>
-
list<T>::node& list<T>::begin(){ //error in this line.
-
return *first;
-
};
-
template <class T>
-
void list<T>::push_back(T& t){
-
node *n={0,&t,0};
-
if(front==0){
-
first = n;
-
last = n;
-
}else{
-
last->next=n;
-
n->prev=last;
-
last = n;
-
}
-
}
-
template <class T>
-
void list<T>::pop_back(){
-
if(last == first){
-
last=0;
-
first=0;
-
}else{
-
last->prev->next=0;
-
last=last.prev;
-
}
-
}
-
-
template <class T>
-
void list<T>::print_list(){
-
node* p = front;
-
while(p!=0){
-
p=p->next;
-
cout << p->data << "-";
-
}
-
cout << endl;
-
};
-
-
4 3933 Banfa 9,065
Recognized Expert Moderator Expert
Really you should post some text explaining your problem as well as the code.
However your problem is that you have declared your structure as private to the class but you are returning it from a public function. The code calling the function will not have access to the type because it is private to the class so this leads to an inconsistency which the compiler is picking up.
I have a similar problem with my code. Pretty much what I would like to know is how do I return a structure that was created within a class. Here is what I have:
Header: - class Tile
-
{
-
private:
-
SDL_Rect tile;
-
string type;
-
string texture;
-
int clip_num;
-
int col_num;
-
int ID;
-
struct warp_coords
-
{
-
string name;
-
int x;
-
int y;
-
}warp;
-
struct playerStart_coords
-
{
-
int x;
-
int y;
-
}playerStart;
-
public:
-
Tile( int x, int y, string a, string b, int c, int d );
-
string get_type();
-
string get_texture();
-
warp_coords get_warp();
-
playerStart_coords get_playerStart();
-
int get_ID();
-
int get_clip_num();
-
int get_col_num();
-
void show();
-
};
k so I wanna return the structure warp and playerStart so I made:
Code: - warp_coords Tile::get_warp()
-
{
-
return warp;
-
}
-
-
playerStart_coords Tile::get_playerStart()
-
{
-
return playerStart;
-
}
my errors are
'warp_coords' does not name a type
'playerStart_co ords' does not name a type
I thought you could return structures like int string char and stuff like that. Any help would be great.
Like the compiler says, 'warp_coords' and 'playerStart_co ords' are not types.
However, Tile::warp_coor ds and Tile::playerSta rt are types.
thanks it works great and I would have never figured it out
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Chris Mantoulidis |
last post by:
I have an abstract class BaseDate and have declared its functions as
pure virtual.
Then I have another class MathDate whose parent is BaseDate.
In base date I have this functions (among others):
virtual BaseDate * set_day(int) = 0;
I've got that function for month and year handling as well. I wanted
|
by: Russell Shaw |
last post by:
Hi,
I have two structs in a header file, and they reference each other,
causing a compile error. Is there a standard way to deal with this?
typedef struct {
...
RtAction *actions;
} RtWidget;
|
by: S.Tobias |
last post by:
I'm trying to understand how structure type completion works.
# A structure or union type of unknown
# content (as described in 6.7.2.3) is an incomplete type. It
# is completed, for all declarations of that type, by
^^^
# declaring the same structure or union tag with its defining
# content later in the same scope.
^^^^^
(6.2.5#23)
|
by: Chris |
last post by:
Hi,
I don't get the difference between a struct and a class !
ok, I know that a struct is a value type, the other a reference type, I
understand the technical differences between both, but conceptually speaking
: when do I define something as 'struct' and when as 'class' ?
for example : if I want to represent a 'Time' thing, containing :
- data members : hours, mins, secs
|
by: thomson |
last post by:
Hi all,
Would you please explain me where will be the heap stored if it
is declared inside the Class, As class is a reference type, so it gets
stored on the heap, but struct is a value type-stored on the stack
Regards
thomson
| |
by: benben |
last post by:
Given a class template Vector<>, I would like to overload operator +.
But I have a hard time deciding whether the return type should be
Vector<U> or Vector<V>, as in:
template <typename U, typename V>
Vector<U_or_V> operator+ (
const Vector<U>&,
const Vector<V>&);
|
by: Michael Rasmussen |
last post by:
Hi all,
Not sure if this is OT?
I have a function in a library written in C++ which returns a
strdup(s.c_str()) to an application written i C. Running Valgrind on my
C-application shows this results in memory leaks due to the c_str is never
freed.
Example:
|
by: Pietro Cerutti |
last post by:
i Group,
to my understanding, defining a function parameter as "const" means that
the function is not going to change it.
Why does the compiler says "return discards qualifiers from pointer
target type" when I *access* a member of an argument defined as const?
Please see the code below:
|
by: beet |
last post by:
Hi all,
I tried to declare a c++ struct like following in a header file; I
want to include
this header file in other files to create and access this struct.
------
1 #ifndef _SEARCHDATA_H_
2 #define _SEARCHDATA_H_
3
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |